I have a settings bar button item (set as left bar button item). I only want to display it if the user is logged in.
I thought I could use the following for anonymous users
navigationItem.leftBarButtonItem = nil
But then how would I show it as soon as they logged in?
Used below simple code :
Declaration :
In ViewDidLoad() or ViewWillAppear() or where you want to hide it : [hide bar button]
where you want to show bar button : [use anywhere in your code]
I have more that 2 menuitems and remove/add menuitem is an overhead. This code snippet worked for me.
Best Way is just custom your Bar buttom with image. Set
barbuttom.image = nil
to Hide again assign the image to show. And dont forget to make the barbutton isEnabled as false.You can store a copy of the leftBarButtonItem in a
strong
property and update it after the users log in.Inside
viewDidLoad
:In logic: