【问题标题】:Push view controller not working in Swift推送视图控制器在 Swift 中不起作用
【发布时间】:2020-05-19 11:13:54
【问题描述】:
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let playGameViewController = (storyboard.instantiateViewController(withIdentifier: "PlayGameViewController") as! PlayGameViewController)
        self.navigationController?.pushViewController(playGameViewController, animated: true)

push 不起作用,但我尝试了当前的工作,我想用 push 导航。

【问题讨论】:

  • 请解释到底是什么不工作。
  • 不改变视图控制器
  • 您确定您的navigationController 不是nil

标签: ios swift uinavigationcontroller storyboard


【解决方案1】:

尝试运行以下代码以了解您哪里出错了。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let playGameViewController = storyboard.instantiateViewController(withIdentifier: "PlayGameViewController") as? PlayGameViewController else {
    print("This means you haven't set your view controller identifier properly.")
    return
}
guard let navigationController = navigationController else {
    print("This means you current view controller doesn't have a navigation controller")
    return
}
navigationController.pushViewController(playGameViewController, animated: true)

尝试使用断点来确定是否有任何变量为零。在您的情况下,您的 navigationController 为 nil 的可能性更大。

【讨论】:

  • 这将有助于识别问题,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多