我将导航栏与tabbarcontroller一起使用。当我按下其中一个标签时,我的导航栏右侧项目会自动隐藏。
我如何将物品移至儿童控制者?
答案 0 :(得分:1)
您可以创建基本视图控制器并从基本视图控制器继承子类,然后调用super.viewDidLoad()
1-基本控制器
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let myButton = UIBarButtonItem(title: "LogOut", style: .done, target: self, action: #selector(self.logoutTapped(_:)))
self.navigationItem.rightBarButtonItem = myButton
}
@objc func logoutTapped(_ sender: UIBarButtonItem) {
print("Logout clicked :) ")
}
}
2- VC一
class ViewController: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}
3- VC两个
class ViewController2: BaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}
结果