2015-10-06 50 views
0

我有一個表視圖,並在選擇單元格表視圖我已經把下面的代碼推動控制器。代碼如下但它不在這裏工作:導航控制器不推動另一個視圖

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) 

} 

回答

0

這絕對不行!

您正在創建一個新的UINavigationController對象並試圖將SecondViewController放入其中。最終沒有任何東西被添加到可見視圖層次結構中,即在視圖控制器之上。

而是實例化一個新的UINavigationController對象,試試這個:

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

PS:爲了更好的命名規則,我代替secondsecondViewController

+0

感謝其工作,但一個問題是,我覺得有些困在推...此外它顯示了一個黑色的屏幕,而不是我已經給出的紅色 –

+0

這是一個不同的問題,你處理視圖控制器的方式。檢查目標視圖控制器的實現。我所建議的是推動新視圖控制器的標準方式。除此之外,如果您在推動VC時發現一些問題,則可能需要更多詳細信息才能解決問題! – Abhinav

相關問題