Reputation: 25
This is pretty straightforward, I have a view which is called when user tap "+" button on top navigation bar in my first view, then, second view appear. My problem is, I can't set any button on my second view navigation bar, actually I tried to set it like I usually did, like I set my "+" button, but nothing works. This is how I set button:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addProduct:)];
self.navigationItem.leftBarButtonItem = addButton;
Then I call my second view:
BIDAddProductViewController *addProductVC = [[BIDAddProductViewController alloc] init];
[self presentModalViewController:addProductVC animated:YES];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hideModalViewController:) name:@HideModalViewController" object:addProductVC];
Please, help me to set button on my second (BIDAddProductViewController) view, nothing's working, I don't know why.
Upvotes: 1
Views: 390
Reputation: 35626
The problem is the way you're presenting the second controller. Instead of pushing it into the navigation stack, you present it modally and that's why you don't get a 'back' button. What you really should be doing is something like this:
BIDAddProductViewController *addProductVC = [[BIDAddProductViewController alloc] init];
[self.navigationController pushViewController:addProductVC animated:YES];
Upvotes: 1
Reputation: 11993
You set the back button on the initial view. If you think about it, it kind of makes sense, the button is 'for' the initial view, so the initial view gets to decide that it says. Default is the initial views title, but you can change it like below
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addProduct:)];
self.navigationItem.leftBarButtonItem = addButton;
self.navigationItem.backBarButtonItem.title = @"Back";
Upvotes: 1