ios - 使用 Swift 5 将一个 View Controller 导航到另一个 View Controller 不起作用

标签 ios viewcontroller swift5

好的,伙计们,在你们的帮助下我已经解决了这个问题,

错误已经消失。

但是页面不会移动到“requirementVC”,因此当我单击该按钮时,它不会执行任何操作。

@IBAction func buttonOK(_ sender: Any) {

    let button = (self.storyboard?.instantiateViewController(withIdentifier: "RequirementsVC") as! requirementVC)
    self.navigationController?.show(button, sender: nil)

}

再次感谢您,点赞!

最佳答案

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

@IBAction func buttonOK(_ sender: Any) {

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

}

这里Main是 Storyboard的名称。

RequirementsVC 应该是在 Storyboard 中设置的 Storyboard id。

并且requirementsVC应该是UIViewController的子类。

//Class name should always start with capital letter. So rename requirementsVC to "RequirementsVC"
class RequirementsVC: UIViewController {

    //class body

}

关于ios - 使用 Swift 5 将一个 View Controller 导航到另一个 View Controller 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59066841/

相关文章:

ios - 如何在 swift 中从树数据结构制作 UIButtons

ios - 在点击图像时打开 View

ios - Swift 5 和 iOS 13 UISearchController 错误的呈现和关闭行为

ios - 从 ViewController 转换到 SelectedIndex 处的选项卡

ios - collectionView didSelectItemAtIndexPath 在迁移到 Xcode 10.2 后停止工作

swift - 如何在 RxSwift 中将多个数据模型绑定(bind)到 TableView

ios - 子类 UINavigationBar SWIFT

ios - 使用 presentViewController :animated:completion: in iOS 8 时 presentingViewController 为 nil

ios - 混音器 AudioUnit 到 RemoteIO AudioUnit

ios - 我无法将 TableViewCell 按钮连接到 TableViewController!如何将值从 TableViewCell 连接到 TableViewController?