0

我的应用程序中有两个视图控制器。根视图控制器有一些组件,其中一个是按钮。该按钮提供使用当前功能打开另一个视图控制器。点击按钮时打开的第二个视图控制器(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)
}
4

1 回答 1

0

您必须推送 SelectTimeViewController 而不是现在

或者如果你真的想展示它,你应该展示另一个 UINavigationController,它的 rootViewController 为 SelectTimeViewController()

于 2019-10-15T16:32:32.690 回答