如何在 Swift 中模态呈现导航控制器?

发布于 2025-01-16 15:08:42 字数 868 浏览 4 评论 0原文

我试图以模态方式呈现一个导航控制器,问题是我的导航栏没有显示任何 baritems...有什么想法吗?这是我的代码。如果我向导航栏添加背景颜色,它实际上会显示,但不会显示按钮...请帮忙!

if let navigationController = baseController as? UINavigationController {
    if UIScreen.main.traitCollection.userInterfaceIdiom == .phone {
        navigationController.present(webViewController, animated: true, completion: nil)
    } else {
        let webNavigationController = UINavigationController(rootViewController: webViewController)
        webNavigationController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(cancelTapped))
        webNavigationController.isNavigationBarHidden = false
        webNavigationController.modalPresentationStyle = .overFullScreen
        navigationController.present(webNavigationController, animated: true, completion: nil)
    }
}

I am trying to present a navigation controller modally,the thing is my navigation bar is not showing any baritems... any ideas? This is my code. If I add a backgroud color to the navigation bar it actually shows, but not the buttons... Please help!

if let navigationController = baseController as? UINavigationController {
    if UIScreen.main.traitCollection.userInterfaceIdiom == .phone {
        navigationController.present(webViewController, animated: true, completion: nil)
    } else {
        let webNavigationController = UINavigationController(rootViewController: webViewController)
        webNavigationController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(cancelTapped))
        webNavigationController.isNavigationBarHidden = false
        webNavigationController.modalPresentationStyle = .overFullScreen
        navigationController.present(webNavigationController, animated: true, completion: nil)
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从来不烧饼 2025-01-23 15:08:42

这行代码是错误的:

webNavigationController.navigationItem.leftBarButtonItem = UIBarButtonItem(...

不是 webNavigationControllernavigationItem 指示了栏按钮项的存在,而是 webViewController

This line is wrong:

webNavigationController.navigationItem.leftBarButtonItem = UIBarButtonItem(...

It is not webNavigationController whose navigationItem dictates the presence of bar button items, but rather webViewController.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文