【问题标题】:Switching between View Controllers (with simultaneous VCs)在视图控制器之间切换(同时使用 VC)
【发布时间】:2018-12-28 14:42:02
【问题描述】:

目前,我有一个主 ViewController 调用 GameViewController 在主 ViewController 前面加载一个 SKScene。我在主 ViewController 的 viewDidLoad 中通过:

let gameView = self.storyboard?.instantiateViewController(withIdentifier: "Game") as! GameViewController
let top: UIViewController? = UIApplication.shared.keyWindow?.rootViewController
top?.present(gameView, animated: false, completion: nil)

这目前有效,我将SKScene 显示在ViewController 之上,该ViewController 在背景中显示图像(带有ImageView)。

但是,现在我想切换到另一个ViewController,但我不知道该怎么做。我尝试过的事情:

  • Segues(用 performSegue(withIdentifier: "mySegueID", sender: nil) 调用它们) 不工作

  • 推送新的ViewController(带navigationController?.pushViewController(nextViewController, animated: true)) 不工作

  • 呈现新的ViewController(使用与显示GameViewController相同的代码)

这个“当前的 VIEWCONTROLLLER”工作正常。但是,在我调用下一个ViewController 然后通过新ViewController 中的按钮按下触发的segue 将其解除后,新的ViewController 将不再使用“当前ViewController”方法再次调用。

关于如何在ViewControllers 之间成功切换的任何想法(其中一个同时拥有GameViewController)?

【问题讨论】:

  • 保留这些导航堆栈的更好方法。 (推和弹出)。但是你展示它们然后不要使用segue。

标签: ios swift uiviewcontroller segue uistoryboardsegue


【解决方案1】:

我想知道为什么 segues 对你不起作用? 您需要给 segue 一个标识符,然后在某些函数或操作(如 buttonPressed)或某些东西中调用它。 在 performSegue(withIdentifier:“urSegueIdentifier”,发件人:Any?.self) 我不确定 sender 是否可以为 nil,也许试试 .self?

【讨论】:

  • 非常感谢!!我发布了我的 segue 不起作用,因为我在解雇 UIImagePicker 时正在调用它。如果我在 segue 中添加延迟,它会始终如一地工作!再次感谢:)
猜你喜欢
  • 2012-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-25
  • 2019-04-10
  • 1970-01-01
相关资源
最近更新 更多