gpt4 book ai didi

swift - NavigationController 看不到右栏按钮项

转载 作者:行者123 更新时间:2023-11-28 12:17:44 26 4
gpt4 key购买 nike

我试图通过允许用户添加算命应用程序的新结果来理解演示 View Controller 。当用户点击导航栏右上角的“添加新结果”时,会弹出一个新的 View Controller ,用户可以在此处输入新结果。我试图在演示 Controller 的右上角添加一个完成按钮,但我收到一条错误消息,提示 Value of type 'UINavigationController?'没有成员“rightBarButtonItem”

我认为这是因为引用 topViewController 是问题所在,但我在 1 个 ViewController 中完成了这一切。

@IBAction func actionButtonTapped(_ sender: UIBarButtonItem) {
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

let viewController = storyboard.instantiateViewController(withIdentifier: "AddNewOptionController")
viewController.modalPresentationStyle = .popover
let popover : UIPopoverPresentationController = viewController.popoverPresentationController!
popover.barButtonItem = sender
popover.delegate = self
present(viewController, animated: true, completion: nil)
}

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
return .fullScreen
}

func presentationController(_ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
let navigationController = UINavigationController(rootViewController: controller.presentedViewController)
let doneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(ViewController.dismissViewController))
//error below
navigationController.topViewController?.navigationController.rightBarButtonItem = doneButton
return navigationController
}

func dismissViewController() {
self.dismiss(animated: true, completion: nil)
}

最佳答案

代替:

navigationController.topViewController?.navigationController.rightBarButtonItem = doneButton

尝试:

navigationController.topViewController?.navigationItem.rightBarButtonItem = doneButton

关于swift - NavigationController 看不到右栏按钮项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45890082/

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