如果視圖被推動或呈現由許多方式可以檢測:
1)檢測導航控制器(推動)
if self.navigationController?.viewControllers.count > 0
{
if self.NavigationItem != nil
{
self.NavigationItem!.setLeftBarButtonItem(nil, animated: false)
self.NavigationItem!.setRightBarButtonItem(nil, animated: false)
}
}
2)的所有腦幹檢測是否視圖(提交模態)
if self.presentingViewController != nil
{
//View is presented
}
然後顯示/隱藏按鈕,您可以使用
for item in self!.navigationItem.leftBarButtonItems! // may be rightBarButtonItems!
{
item.enabled = true
item.tintColor = UIColor.whiteColor() You can change color
}
// To hide items
if self.navigationItem.leftBarButtonItems != nil
{
for item in self.navigationItem.leftBarButtonItems!
{
item.enabled = false
item.tintColor = UIColor.clearColor()
}
}
,或者你可以設置按鈕作爲零
if self.NavigationItem != nil
{
self.NavigationItem!.setLeftBarButtonItem(nil, animated: false)
self.NavigationItem!.setRightBarButtonItem(nil, animated: false)
}
感謝!這正是我一直在尋找。 – slonkar