1

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.

2 Answers 2

1

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]; 
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your help Alladinian, but when im tryint to add [self.navigationController pushViewController:addProductVC animated:YES]; programm return error Sigabrt.
Have you properly initialized a UINavigationController and set your first controller as the rootViewController ? Here is the relevant documentation
I guess i didnt for that one view (actualy below lies TableView with massiva array of elements and detail view for each one), i just grab and drop NavigationController from object Library to top. Thank you for link
1

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"; 

1 Comment

Thanks trapper, i added self.navigationItem.backBarButtonItem.title = @"Back"; but nothing has changed :(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.