如何在没有控制器的情况下推送视图控制器



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

我使用 UIKIt + Swift 5

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

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

我怎么能这样

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

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

试试这段代码

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

相关内容

最新更新