gpt4 book ai didi

ios - 向 UINavigationItem 添加按钮根本不起作用

转载 作者:行者123 更新时间:2023-11-30 13:27:10 24 4
gpt4 key购买 nike

我确信我以前使用过这种模式,但有些东西阻止我将 UIBarButtonItems 添加到我的子类 UINavigationController

// AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.mainScreen().bounds);
let plainVC = UIViewController();
plainVC.title = "Plain";
let explorerNav = ExplorerNavController(rootViewController: plainVC);
window?.rootViewController = explorerNav;
window?.makeKeyAndVisible();
return true
}

//ExplorerNavController
class ExplorerNavController: UINavigationController {

override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Dumb", style: .Done, target: self, action: #selector(openSettings));
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Done, target: self, action: #selector(openSettings));
}

func openSettings(){
print("did tap open settings");
}
}

这给我留下了: enter image description here

我还尝试设置 View Controller 的导航项,在 viewDidAppear 而不是 viewDidLoad 中设置项。我可以在设置导航项时使用相同的 viewDidLoad 设置导航栏的样式,从而证明实际上正在创建 ExplorerNavController 的实例。我只是不确定我错过了什么。

最佳答案

用途:

let leftBarButtonItem = UIBarButtonItem(title: "Dumb", style: .Done, target: self, action: #selector(openSettings))
nav.navigationItem.setLeftBarButtonItem(leftBarButtonItem, animated: true)

关于ios - 向 UINavigationItem 添加按钮根本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37034649/

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