Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 612
LiangWang Avatar asked Mar 27 '26 05:03

LiangWang


1 Answers

The first, i.e. 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.

like image 88
mattjgalloway Avatar answered Mar 29 '26 20:03

mattjgalloway