Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is self.navigationItem.backBarButtonItem always nil?

I push a view controller onto a navigation controller like this:

[self.navigationController pushViewController:anotherViewController animated:YES];

And, then, inside anotherViewController I check self.navigationItem.BackBarButtonItem and LeftBarButtonItem, but they are always nil.

I can see the backBarButtonItem, and it seems to work fine.

like image 551
Michael T Avatar asked Aug 03 '11 21:08

Michael T


People also ask

How to hide back button iOS?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How to hide navigation bar back button in iOS Swift?

Basic Swift Code for iOS Apps To hide the back button on navigation bar we'll have to either set the navigation button as nil and then hide it or hide it directly. Let's create a project, add 2 view controller and Embed them in navigation controller.


1 Answers

From the Documentation: "When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a back button on the navigation bar. Use this property to specify the back button. The target and action of the back bar button item you set should be nil. The default value is a bar button item displaying the navigation item’s title."

I'm taking this to mean that it is convention for it to always be nil, and that the default value is always nil.

A similar subject about self.navigationItem.backBarButtonItem being nil was discussed here: Changing the UIBackButtonItem title

like image 80
rich Avatar answered Sep 30 '22 20:09

rich