我创建了
NavigationController(Main) - > LoginViewController - > Tabbarviewcontroller - > HomeViewController
如果我通过storyboard在HomeViewController中添加barbutton项目,它就不会在模拟器中显示。
但我可以看到故事板中的变化。
标题Home1和barbutton项目未在模拟器中显示
答案 0 :(得分:0)
首先在NavagationController中隐藏导航栏,然后创建自定义栏。在栏中添加所需的栏。
答案 1 :(得分:0)
您可以通过编程方式尝试
HomeViewController ---
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
let barButtomitem = UIBarButtonItem(barButtonSystemItem: .Done, target: self, action: #selector(handler))
self.tabBarController?.navigationItem.rightBarButtonItem = barButtomitem
}
SecondItemViewController -
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
self.tabBarController?.navigationItem.rightBarButtonItem = nil
}
并且不要在故事板中添加按钮...
答案 2 :(得分:0)
试用此代码:在Swift 3中测试:
注意:删除所有barButtonItems并尝试下面的代码。
将此代码添加到Home1 VC:
override func viewWillAppear(_ animated: Bool) {
let RightButtomitem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(handler))
self.tabBarController?.navigationItem.rightBarButtonItem = RightButtomitem
}
func handler(sender:UIButton) {
print("Add Button pressed")
}
将此代码添加到Home2 VC:
override func viewWillAppear(_ animated: Bool) {
let RightButtomitem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(handler))
self.tabBarController?.navigationItem.rightBarButtonItem = RightButtomitem
}
func handler(sender:UIButton) {
print("Done Button Pressed")
}
输出: