gpt4 book ai didi

swift - NavigationBar 右侧项目在显示内部 ViewController 时隐藏

转载 作者:行者123 更新时间:2023-11-28 13:53:48 25 4
gpt4 key购买 nike

我将导航栏与 tabbarcontroller 一起使用。当我按下其中一个选项卡时,我的导航栏右侧项目会自动隐藏。

如何将我的项目移动到子 Controller ?

最佳答案

您可以创建基础 View Controller 并从基础 View Controller 继承您的子类,然后调用 super.viewDidLoad()

1- 基地 Controller

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-风投一

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.
}

}

结果

enter image description here

关于swift - NavigationBar 右侧项目在显示内部 ViewController 时隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54161601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com