Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding UINavigationItem's bar button

I have added a BarButton item to the left of the nav.bar through Interface Builder and in the code I want this only to show in my table view's edit mode. But I didn't find any hidden property to set the leftBarButtonItem (like: self.navigationItem.leftBarButtonItem.hidden = YES).

I can only set enabled property. Anybody know how to control the hide and show property of the leftBarButtonItem, please help.

like image 795
Sreehari Avatar asked Aug 04 '09 08:08

Sreehari


People also ask

How do I hide items in navigation?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I hide UIBarButtonItem?

There is no way to "hide" a UIBarButtonItem you must remove it from the superView and add it back when you want to display it again.

How can hide back button in IOS?

To hide the back button on navigation bar we'll have to either set the navigation button as nil and then hide it or hide it directly. Let's create a project, add 2 view controller and Embed them in navigation controller.


2 Answers

This works I tried it myself

self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = YES;      
like image 102
Adrian Avendano Avatar answered Oct 05 '22 23:10

Adrian Avendano


I'm pretty sure the only way to "hide" it is to nil it out.

self.navigationItem.leftBarButtonItem = nil;

Though it's not a perfect answer to your question, since that basically gets rid of your button instead of hiding it. You'll either have to recreate it or keep your original button around and simply set the leftBarButtonItem back to your UIBarButtonItem.

like image 40
Neil Avatar answered Oct 05 '22 23:10

Neil