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?
You can store a copy of the leftBarButtonItem in a strong
property and update it after the users log in.
var leftBarButtonItem : UIBarButtonItem!
Inside viewDidLoad
:
self.leftBarButtonItem = UIBarButtonItem(title: "test", style: UIBarButtonItem.Style.Plain, target: nil, action: nil)
In logic:
if loggedIn
{
self.navigationItem.leftBarButtonItem = self.leftBarButtonItem
}
else
{
self.navigationItem.leftBarButtonItem = nil
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With