我如何在 swift 5 上工作推送视图控制器?

cod*_*r86 1 swift

CollectionView或TableView中的Didselect函数;

let trial = TrialViewController ()
self.navigationController?.pushViewController (trial, animated: true)
Run Code Online (Sandbox Code Playgroud)

我想转到另一个页面,但它没有响应。当我打字时,同样的事情也在发生。

self.present (den, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

当我打字时正在工作。

为什么pushViewController不工作?

谢谢

Sh_*_*han 5

看来self.navigationController?nil

带故事板:

self.navigationController?.pushViewController (trial, animated: true) 
Run Code Online (Sandbox Code Playgroud)

确保当前的 vc 嵌入在 navigationController 中

在此输入图像描述

没有故事板:

里面didFinishLaunchingWithOptions

self.window?.rootViewController = UINavigationController(root:ViewController())
Run Code Online (Sandbox Code Playgroud)