如何在 Swift 中以模态方式呈现导航控制器?
How to modally present a navigation controller in 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)
}
}
这一行是错误的:
webNavigationController.navigationItem.leftBarButtonItem = UIBarButtonItem(...
不是 webNavigationController
的 navigationItem
决定了栏按钮项目的存在,而是 webViewController
。
我正在尝试以模态方式呈现导航控制器,问题是我的导航栏没有显示任何 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)
}
}
这一行是错误的:
webNavigationController.navigationItem.leftBarButtonItem = UIBarButtonItem(...
不是 webNavigationController
的 navigationItem
决定了栏按钮项目的存在,而是 webViewController
。