Why is self.navigationItem.backBarButtonItem always nil?

走远了吗. 提交于 2020-01-02 01:01:15

问题


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



来源:https://stackoverflow.com/questions/6933280/why-is-self-navigationitem-backbarbuttonitem-always-nil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!