Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constant UIBarButtonItem in UINavigationController

Is there any way that I can have a UINavigationController and have it always display the same UIBarButtonItem no matter how many times it is pushed?

like image 796
jonathan Avatar asked Nov 13 '22 17:11

jonathan


1 Answers

Try this-

  1. Create subclass(CustomNavigationController) of UINavigationController & use it to push your view controllers.
  2. In CustomNavigationController create UIBarButtonItem in init or in viewDidLoad. Add target & action to it.
  3. Implement UINavigationControllerDelegate delegates in CustomNavigationController and set barButtonYouCreated as right or left bar button item for each view controller in delegate method.

Use

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
     viewController.navigationItem.leftBarButtonItem = barButtonYouCreated;
}

or

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
like image 187
Rahul Wakade Avatar answered Nov 15 '22 05:11

Rahul Wakade