2016-01-13 57 views
1

我尝试在一个FUNC开第二视图控制器但出现这种错误:需要试图提出<UINavigationController的>上firstController其视图不在窗口层级

Attempt to present <UINavigationController> on firstController whose view is not in the window hierarchy!

所有溶液:

要么把代码内viewWillAppear() 或内部IBAction FUNC

我的程序需要从正常FUNC

打开第二视图控制器0

我尝试了所有这代码:

代码1:

self.performSegueWithIdentifier("page2", sender:self) 

结果:

error: has no segue with identifier 'page2''

代码2:

let secondViewController:page2 = page2() 
self.presentViewController(secondViewController, animated: true,completion: nil) 

RES ULT:

error: whose view is not in the window hierarchy!

代码3:

let nextViewController = storyboard!.instantiateViewControllerWithIdentifier("next2") as! UIViewController 
self.presentViewController(nextViewController, animated:true, completion:nil) 

结果:

fatal error: unexpectedly found nil fwom win func

代码4:

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) 
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("next2") as! page2 
self.presentViewController(nextViewController, animated:true, completion:nil) 
    dismissViewControllerAnimated(true, completion:nil) 

结果:

error whose view is not in the window hierarchy!

我需要一个解决方案,请。

+0

塞格可能是你的第一个考虑因素,但塞格标识符并不是视图的名称。您需要将第一个视图连接到故事板中的导航视图,并给出一个标识符以便能够使用此功能。 – zcui93

+0

是的,我让segue的名字是第2页的代码和故事板中,我也改变了segue的名字到另一个名字,但它不工作 – ematalb

+0

在故事板中有你的segue的截图应该有所帮助。 – zcui93

回答

0

你会想要使用代码1,但在故事板中,您需要从包含您的代码的ViewController到您要显示的ViewController的segue。 (Ctrl +从ViewController“所有者”图标拖到第二个ViewController)

然后点击这个segue,并在检查器中确保segue用于运行赛格。

+0

我做这个,但它不工作 – ematalb

相关问题