Hide the rightBarButtonItem of a navigation controller

user347161 picture user347161 · Jun 15, 2010 · Viewed 18.8k times · Source

Does anyone know how to hide a rightBarButtonItem of a UINavigationController? In my application, I have an edit button as a rightBarButtonItem of a UINavigationController. I want to hide this ? UIBarButton` when some operations are done.

Answer

MyCSharpCorner picture MyCSharpCorner · Nov 12, 2011

To Hide the right button: self.navigationItem.rightBarButtonItem = nil;

Now, to show it:

  1. If you setup the right button in your view controller by assigning it to self.editButtonItem then simply assign it again in order to show it:

    self.navigationItem.rightBarButtonItem = self.editButtonItem;

  2. If you setup the right button in your view controller by allocating and initing a UIBarButtonItem, then simply keep a reference to the UIBarButtonItem in your view controller, and assign it again when you need to show it.