【问题标题】:How to push view controller without controller如何在没有控制器的情况下推送视图控制器
【发布时间】:2019-08-31 16:59:35
【问题描述】:

我想推送视图控制器,但我的 collectionViewController 中没有导航,我想转到另一个控制器

我使用 UIKIt + Swift 5

 override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {


        navigationController?.pushViewController(InternalController(), animated: true)
    }

我是怎么做到的

【问题讨论】:

    标签: swift uikit


    【解决方案1】:

    只需实例化新的 ViewController 并呈现它:

    let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
    let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
    self.present(controller, animated: true, completion: nil)
    

    【讨论】:

      【解决方案2】:

      试试这个代码

      if let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginView") as? LoginViewController {
          present(vc, animated: true, completion: nil)
      }
      

      【讨论】:

        猜你喜欢
        • 2011-09-11
        • 1970-01-01
        • 2010-12-11
        • 2013-08-28
        • 1970-01-01
        • 2011-06-26
        • 2017-08-09
        • 2012-08-22
        • 1970-01-01
        相关资源
        最近更新 更多