Added Button does not show on UINavigationController
cocoa-touch, objective-c, uiviewcontroller
Solution
Change
navigationController.navigationItem.leftBarButtonItem = closeButton;
to
tempViewController.navigationItem.leftBarButtonItem = closeButton;
The `navigationItem` appearance is handled by the view which is being presented by the nav controller, so if you set it on the `UINavigationController` but not on the `rootViewController`, it gets overridden when you push it the first time.
Problem
I am trying to create a viewcontroller on the fly and set its view and title bar. Things seems to work just fine. But when I try to set the left button or right button of the navigation bar, they just do not show up. what am I doing wrong? ``` UIWebView *tempWebView = [[UIWebView alloc] initWithFrame:self.view.bounds]; [tempWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"someurl"]]]; UIViewController* tempViewController = [[UIViewController alloc]init]; tempViewController.view = tempWebView; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tempViewController]; UIBarButtonItem* closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:nil]; navigationController.navigationItem.leftBarButtonItem = closeButton; [self presentViewController:navigationController animated:YES completion:nil]; ```