-->

Why is self.navigationItem.backBarButtonItem alway

2020-08-12 03:13发布

问题:

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.

回答1:

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