导航控制器不推动另一个视图

Navigation controller not pushing another view

我有一个 table 视图,在 select 单元格 table 视图中,我放置了以下代码来推送控制器。代码在下面,但它在这里不起作用:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    println("You selected cell #\(indexPath.row)!")
    let second: SecondViewController = SecondViewController()
    let navigat = UINavigationController()
    navigat.pushViewController(second, animated: true)

}

这永远行不通!

您正在创建一个新的 UINavigationController 对象并试图将您的 SecondViewController 推入其中。最终没有任何东西被添加到可见视图层次结构中,即在你的视图控制器之上。

不要实例化一个新的 UINavigationController 对象,试试这个:

self.navigationController?.pushViewController(secondViewController, animated: true)

PS:为了更好的命名约定,我将 second 替换为 secondViewController