简体   繁体   中英

self.navigationItem.rightBarButtonItem vs self.navigationController.navigationItem.rightBarButtonItem

I'm somewhat confused about using self.navigationItem.rightBarButtonItem and self.navigationController.navigationItem.rightBarButtonItem .

Which one is correct way?

The first, ie self.navigationItem.rightBarButtonItem .

Every view controller has an associated navigation item. This is what is displayed in a navigation bar. So it's the current view controller's navigation item that you want to manipulate. If you manipulated the navigation controller's navigation item then that would show if the navigation controller (also a view controller) were itself shown inside another navigation controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM