【问题标题】:Warning: Attempt to present <GuessMeFinal> on <GuessMeFinal.ViewController> whose view is not in the window hierarchy -Swift警告:尝试在 <GuessMeFinal.ViewController> 上呈现 <GuessMeFinal>,其视图不在窗口层次结构中 -Swift
【发布时间】:2015-11-16 00:16:54
【问题描述】:

好的..这就是问题所在。当我点击主菜单中的[播放]按钮时,它应该根据这段代码进入相应的ViewController:

@IBAction func playButton(sender: AnyObject) {

    if  rightCounter <= 4  {
        if let Level1 = self.storyboard!.instantiateViewControllerWithIdentifier("Level1") as? Level1 {
            self.presentViewController(Level1, animated: true, completion: nil)


        }
    }


        if rightCounter >= 5 && rightCounter <= 9 {


            if let Level2 = self.storyboard!.instantiateViewControllerWithIdentifier("Level2") as? Level2 {
                self.presentViewController(Level2, animated: true, completion: nil)
            }


        }



}

代码运行完美!没有错误!但是当 rightCounter 为 9 时,它仍然将我带到第一个 ViewController。实际上它应该带我到第二个 ViewController。这就是我们必须修复的地方。顺便说一句,提前谢谢。

在那段时间里,我也收到了这个错误。 Warning: Attempt to present <GuessMeFinal.Level2: 0x79eb7500> on <GuessMeFinal.ViewController: 0x7ac62180> whose view is not in the window hierarchy!

我已将 mainViewController 连接到 Level1 和 Level2 ViewControllers。那么,我应该使用其他代码来解决我的问题,还是请在这里帮助我!

【问题讨论】:

  • 现在,真正的问题是:代码中没有错误,但我的应用程序没有按照我编写的代码运行。例如:如果我的右侧计数器是 5,我知道它是 5,它应该带我到 Level2 VC,但它仍然带我到 Level1 VC。请帮忙!
  • 可能是因为 MainViewController 无法访问我存储在一个视图控制器中的 rightCounter 值?
  • 我确实在第二个 if 命令的开头放置了一个断点。现在有显示 Thread1: Breakpoint 的绿色突出显示。应用卡住了,上面写着GuessMeFinal[1893:1599218] Could not load the "" image referenced from a nib in the bundle with identifier "com.SKApps.GuessMeFinal"这是什么意思?
  • 为了清楚起见,我已将 rightCounter 值存储在 Level1 VC 和 Level2 VC 中,但未存储在 MainViewController 中。这会是个问题吗?
  • @matt 帮帮我。!请..!

标签: ios iphone xcode swift uiviewcontroller


【解决方案1】:

我以前也遇到过这个问题。当您尝试呈现未嵌入在同一导航/标签栏控制器中的视图控制器时,就会发生这种情况。

这将失败:

如果您尝试呈现突出显示的 segue,您的应用将会崩溃。我不知道这是否是你想要做的,但我之前遇到过这个错误。您可能还想查看this very similar question

希望这会有所帮助。

【讨论】:

  • 我不使用 NavigationController。那么,您认为单击[播放]按钮时没有显示Level2 VC的问题可能是什么?
  • 你使用标签栏控制器吗?
  • 不!只是 ViewControllers
  • 我注意到一件事:第一个 ViewController(“MainStoryBoard”中带有箭头标记的 ViewController)总是返回“0”值。这些值适用于其他 ViewController。那么,可能是什么问题..!帮帮我..拜托..!
猜你喜欢
  • 2014-11-19
  • 1970-01-01
  • 2020-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-23
  • 2017-07-18
  • 1970-01-01
相关资源
最近更新 更多