以这种方式显示ViewController时,即使ViewController嵌入在界面生成器中的导航控制器中,我也没有导航栏。
if let stockVC = storyboard?.instantiateViewController(withIdentifier: "Stock") as? StockTableViewController {
stockVC.stockToDisplay = commonData.stock.filter { $0.productID.contains(product) }
// No NavigationBar with this one
navigationController?.present(stockVC, animated: true)
// No NavigationBar with this one
self.present(stockVC, animated: true)
}
我知道navigationBar可以正常工作,因为如果我将ViewController设置为情节提要中的初始值,它将显示出来。
我在这里做错了什么?
当您提供视图控制器时,它不属于当前导航堆栈。您需要使用stockVC创建一个新的导航控制器,并显示新的导航控制器:
if let stockVC = storyboard?.instantiateViewController(withIdentifier: "Stock") as? StockTableViewController {
stockVC.stockToDisplay = commonData.stock.filter { $0.productID.contains(product) }
let stockNavigationController = UINavigationController(rootViewController: stockVC)
self.present(stockNavigationController, animated: true)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句