1
votes

First, I've read almost all of the questions and answers on the web and SO about navigation bar/back button/title/navigation item etc. I have a navigation controller and view controllers. Nothing fancy. Whatever I do, I can't display a back button when I push a new view controller. Neither via storyboard push segues nor programmatically pushing. My view controller and navigation bar displays correctly, when I tap where where the back button should be, it does work, it pops the view controller, however, it's not displayed.

Before you say, I'll list what I've done:

  • I've got the navigation controller's Shows Navigation Bar set to yes.
  • I've set a title to my root view controller inside the navigation controller on storyboard.
  • I've set a back button title to my root view controller inside the navigation controller on storyboard.
  • I don't have any custom code involving navigation bar/navigation item/left bar button/right bar button/hides back button/back button item.
  • I've set a title for my navigation controller.

Whatever I do, my back button doesn't get displayed. When I debug, it's set to nil. I've tried instantiating one but it didn't help either. What am I missing?

3

3 Answers

1
votes

Firstly check that the controller you are pushing from and to has a navigation item in the viewer you can set title, back button and prompt for. I have found that depending on how storyboard has created the controller it may or may not have one you can see in the view tree. Setting the back button does not seem to work unless you can actually see one in both controllers in storyboard.

Secondly, and something I only realized recently, is that you set the title for the back button in the controller you are pushing "from" and not in the controller that will be showing when the back button is showing.

e.g. If you have controller A and controller B and you are pushing to B from A: you have to set the label for the back button in the navigationItem of controller A, not in the navigationItem of controller B. You may already know this, but its confusing.

0
votes

define a property in .h

@property (strong, nonatomic) UIBarButtonItem *backButton;

in viewDidLoad in .m

self.backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backButton.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed)];
self.navigationItem.backBarButtonItem = self.backButton;

and add the method

-(void) backButtonPressed {

 [self.navigationController popViewControllerAnimated:YES];

}

oh misread... you don t want a custom button, just the normal one? maybe there is a UIBarButtonSystemItem for back ?? take this instead of a custom image...

checked tintcolor? maybe it s set to clearcolor ??

0
votes

It was something much simpler. Actually, everything was acting correctly. After some investigation ([[UIWindow keyWindow] recursiveDescription]) I've realized that it was just me who was faulty to set the storyboard's global tint color to the same color with navigation bar. I've explicitly set the tint to white and now the text is seen.