如何在 Swift 中模态呈现导航控制器?
我试图以模态方式呈现一个导航控制器,问题是我的导航栏没有显示任何 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这行代码是错误的:
不是
webNavigationController
的navigationItem
指示了栏按钮项的存在,而是webViewController
。This line is wrong:
It is not
webNavigationController
whosenavigationItem
dictates the presence of bar button items, but ratherwebViewController
.