gpt4 book ai didi

ios - 尝试在其 View 不在窗口层次结构中的 firstController 上呈现

转载 作者:行者123 更新时间:2023-11-28 08:48:02 25 4
gpt4 key购买 nike

我尝试在一个函数中打开第二个 View Controller ,但出现此错误:

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

所需的所有解决方案:

要么把代码放在viewWillAppear()里面或里面 IBAction函数

我的程序需要从普通函数打开第二个 View Controller

我试过所有这些代码:

代码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)

结果:

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!

我需要一个解决方案。

最佳答案

您将要使用代码 1,但是在您的 Storyboard 中,您将需要从包含您的代码的 ViewController 到您要显示的 ViewController 的转场。 (Ctrl+从 ViewController“所有者”图标拖动到第二个 ViewController)

然后单击此转场,并在检查器中确保转场 (!) 获得名称“page2”——因为此名称用于运行转场。

关于ios - 尝试在其 View 不在窗口层次结构中的 firstController 上呈现 <UINavigationController>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34762267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com