How to hide the uibarbutton item of a navigation bar

rockey picture rockey · Nov 11, 2010 · Viewed 10.4k times · Source

i am unzipping a file on background thread and i am calling HomeViewController on main thread.in this view controller i have a UIBarButtonItem on UINavigationBar. if i click this button it goes to StoryViewController and the unzipped data is used there. so i want to show the Home view Controller though the unzipping process is not completed, for that i have to hide the button on the navigation bar when the unzipping starts on backround thread and after completion of the upzipping again i have to show the button on navigation bar. i am calling the methods of homeViewController to hide and show.. What i have to write in those methods..? i mean how to hide and show the uiBarButtonItem on UINavigationBar....?

Thanks....

Answer

Romain picture Romain · Nov 11, 2010

Once you have created your UIBarButtonItem say "myButton", you can add/remove it to your navigation controller using in your view Controller:

if(show)
    self.navigationItem.leftBarButtonItem = myButton;
else
    self.navigationItem.leftBarButtonItem = nil;