我的应用程序中有两个视图控制器。根视图控制器有一些组件,其中一个是按钮。该按钮提供使用当前功能打开另一个视图控制器。点击按钮时打开的第二个视图控制器(SelectTimeViewController)已成功打开。我正在尝试设置导航标题和项目,但我看不到它们。
我没有使用故事板,所以根视图控制器是从 AppDelegate 设置的。
let viewController = ViewController()
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = UINavigationController(rootViewController: viewController)
window?.makeKeyAndVisible()
当点击按钮时,“openVC”函数被调用。
@IBAction func openVC(_ sender: Any) {
self.navigationController?.present(SelectTimeViewController(), animated: true, completion: nil)
}
我试图在 SelectTimeViewController 的 viewDidLoad 函数中设置 title 和 rightBarButtonItem 但我看不到它们。
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "close"), style: .plain, target: self, action: #selector(closeIt))
self.navigationItem.title = "Select Time"
}
除此之外,当更改“openVC”功能时,我可以看到标题和右栏按钮项,如下所示。
@IBAction func openVC(_ sender: Any) {
self.navigationController?.pushViewController(vc, animated: true)
}