问题:我试图在 View Controller 中获取导航 Controller 的句柄,但它总是返回 nil,下面是我的代码
层次结构:AppDelegate -> MainStoryboard -> 抽屉导航 -> TestStoryboard -> 测试
从抽屉导航中我打开 viewControl,如下所示:
self.openNewStoryBoard(storyBoard: "testingone", scene: "initial")
func openNewStoryBoard(storyBoard:String, scene:String){
let storyboard = UIStoryboard(name: storyBoard, bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: scene) as UIViewController
self.present(controller, animated: true, completion: nil)
}
我的“testingone” Storyboard中有一个导航 Controller ,它通过关系连接到viewContorller“初始” - “ Root View Controller ”到“viewController”,将其连接到testtingone类
在代码(testingOne)类中,我试图获取导航 Controller 的句柄,如下所示:
self.rootNav = self.navigationController!
但结果总是为零
最佳答案
通过直接呈现 View Controller ,您可以完全绕过导航 Controller 。这就是为什么你在调用 self.navigationController
时得到 nil
的原因。您应该显示您的导航 Controller 。
为此,只需在 Storyboard中将导航 Controller 的 Storyboard ID 设置为 initial
而不是 View Controller 。
关于ios - self.navigationController 使用 Storyboard到 Storyboard导航始终返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39778503/