简体   繁体   中英

Swift: navigationController returning nil

On a UIViewController instantiated by a UITabBarController, when I run the following code,

let destination = self.storyboard?.instantiateViewControllerWithIdentifier("test")
self.navigationController!.pushViewController(destination!, animated: true)

navigationController return nil. How can I get navigationController instance to push a view controller?

As @Paulw11 said, what was missing was embed the UIViewController in a navigation controller. To do that, drag-and-drop a Navigation Controller to the Storyboard and CTRL + drag from that Navigation Controller to the UIViewController , chosing the relationship root view controller .

您的源UIViewController实例需要嵌入故事板场景中的UINavigationController中,以便提供要推送到的导航控制器实例。

https://stackoverflow.com/a/32959896/3810914

Exactly. If you did, the error would be resolved

在此处输入图片说明

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM