使用Swift 5将一个View Controller导航到另一个View Controller时出错

问题描述 投票:0回答:1

我想移到另一个视图控制器,但我不断收到错误消息:

无法将类型'App.ViewController'(0x106722db8)的值强制转换为'App.requirementVC'(0x106722d58)。

我已经检查了标识符ID和文件名,都很好。

这是我的代码

@IBAction func buttonOK(_ sender: Any) {

    let button = (self.storyboard?.instantiateViewController(identifier: "RequirementsVC") as! requirementVC)
    self.navigationController?.pushViewController(button, animated: true)

我是新手,所以我需要您的帮助。提前谢谢。

ios viewcontroller swift5
1个回答
0
投票

您可以执行以下操作...

@IBAction func buttonOK(_ sender: Any) {

  let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "RequirementsVC") as! requirementsVC
  self.navigationController?.pushViewController(vc, animated: true)

}

这里Main是情节提要的名称。

© www.soinside.com 2019 - 2024. All rights reserved.