Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在SWIFT中的ViewController之间导航_Ios_Objective C_Swift_Navigation_Viewcontroller - Fatal编程技术网

Ios 在SWIFT中的ViewController之间导航

Ios 在SWIFT中的ViewController之间导航,ios,objective-c,swift,navigation,viewcontroller,Ios,Objective C,Swift,Navigation,Viewcontroller,我正在尝试从一个视图控制器导航到另一个视图控制器。下面是我使用的代码,它似乎不适合我。也不会抛出错误 let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("MainController") as ViewController self.navigationController?.pushViewController(secondViewController, animated: t

我正在尝试从一个视图控制器导航到另一个视图控制器。下面是我使用的代码,它似乎不适合我。也不会抛出错误

let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("MainController") as ViewController
self.navigationController?.pushViewController(secondViewController, animated: true)

我需要帮助解决这个问题。提前感谢。

您的主视图控制器是否嵌入到导航控制器中?如果不是,则可选值navigationContoller?自我价值将为零。如果它是嵌入式的,您能否在运行时检查self.navigationController是否?是否有值?它未嵌入navigationController中。我自己解决了。我将第二行替换为self.presentViewControllersecondViewController,动画:true,完成:{}。无论如何,谢谢。啊,是的,那也行。很高兴你明白了