【问题标题】:Swift: dismissViewController and Instantiate another ViewControllerSwift:dismissViewController 并实例化另一个 ViewController
【发布时间】:2015-12-23 23:55:54
【问题描述】:

我正在尝试关闭视图控制器并同时呈现另一个视图控制器。当Level1Controller() 完成并调用self.dismissViewController() 时,我希望它带我到另一个名为EndScene() 的视图控制器。

这是最接近我的代码。

   self.dismissViewControllerAnimated(true, completion: {() -> Void in
       let storyboard = UIStoryboard(name: "Main", bundle: nil)
       let nextViewConroller = storyboard.instantiateViewControllerWithIdentifier("endscene")
       self.presentViewController(nextViewConroller, animated: false, completion: nil)
   })

【问题讨论】:

  • 您在@Rogue Studios 遇到的实际问题是什么?
  • @RaphaelOliveira 它只会引导我回到根视图控制器,这是错误消息2015-12-23 17:47:35.333 Spin Game[6466:2789372] Warning: Attempt to present <Spin_Game.EndScene: 0x14edc0b20> on <Spin_Game.Level1Controller: 0x14f86d400> whose view is not in the window hierarchy!
  • 知道了,会写答案的。

标签: ios swift uiviewcontroller instantiation dismiss


【解决方案1】:

不要在Level1Controller 上调用dismissViewControllerAnimated,而是在呈现它的视图控制器上调用它。然后在完成块上,您可以以与您相同的方式呈现EndScene。发生错误是因为实际上自从您从窗口中删除了 Level1Controller 之后,使用它来呈现另一个视图控制器是没有意义的。

Window -> ParentViewController (在这里调用dismiss) -> Level1Controller

Window -> ParentViewController(完成时呈现 EndScene)-> EndScene

您可能必须通知Level1Controller 的父级已执行取消操作,您可以通过委托来执行此操作。另一种选择(我没有测试过)是将解雇保留在Level1Controller 并从presentingViewController 呈现。

self.presentingViewController.presentViewController...

不确定在调用完成块时presentingViewController 是否为 nil。

【讨论】:

  • 谢谢,我会尽快尝试。我会告诉你进展如何。
  • 嗨 Rogue,很高兴你解决了你的问题。您最终使用了哪种解决方案?
猜你喜欢
  • 2014-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多