Reputation: 663
I have a button and when pressed it presents a new viewController, like a pop up window.
- (IBAction)btnPressed:(id)sender
{
PopUpObj = [[PopUpViewController alloc] init];
[self.navigationController presentViewController:PopUpObj animated:YES completion:nil];
}
The View appears as it should but it has no nav bar with back button.
In the PopUpViewController I create a nav bar like this:
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor whiteColor];
UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 64)];
[navbar setBarStyle:UIBarStyleDefault];
[self.view addSubview:navbar];
UIBarButtonItem* myBackButton = [[UIBarButtonItem alloc]
initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
self.navigationItem.backBarButtonItem = myBackButton;
[super viewDidLoad];
}
The nav bar appears but the back button item doesn't appear at all. What's wrong?
Upvotes: 0
Views: 52
Reputation: 21536
The backBarButtonItem
is displayed when you push another viewController onto the navigation stack. Think of it as the button that will be used to get back to your PopUpViewController, not the button displayed whilst showing your PopUpViewController. Change self.navigationItem.backBarButtonItem
to self.navigationItem.leftBarButtonItem
.
Upvotes: 1