如何隐藏某些用户的栏按钮项 [英] How to hide a bar button item for certain users
本文介绍了如何隐藏某些用户的栏按钮项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个设置栏按钮项(设置为左栏按钮项)。我只想在用户登录时显示它。
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?
推荐答案
您可以将leftBarButtonItem的副本存储在 strong
属性并在用户登录后将其设置回来。
You can store a copy of the leftBarButtonItem in a strong
property and set it back after the users log in.
var leftBarButtonItem : UIBarButtonItem!
内部viewDidLoad
Inside viewDidLoad
self.leftBarButtonItem = UIBarButtonItem(title: "test", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
逻辑
if loggedIn
{
self.navigationItem.leftBarButtonItem = self.leftBarButtonItem
}
else
{
self.navigationItem.leftBarButtonItem = nil
}
这篇关于如何隐藏某些用户的栏按钮项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文