我試圖在導航控制器中嵌入的ViewController之上呈現嵌入NavigationController中的tableViewController。嘗試在導航控制器之上呈現導航控制器「其視圖不在窗口層次結構中」
I keep getting the error: that the view controller cannot be presented because it is not in the window hierarchy.
總之,我想允許用戶點擊the number of likes
上後,然後被引導至NavigationController嵌入式TableViewController和它不工作。
由於某種原因,當它從標籤欄控制器呈現時工作,當我嘗試點擊類似的數字,但不是當我從導航控制器執行它時。對於點擊等等數如下,位於集合視圖中的細胞迅速的文件的操作代碼:
@IBAction func LikeNumber_tapped(_ sender: Any) {
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LikedByVC2") as? UINavigationController
let tableVC = vc?.viewControllers.first as! LikedByTableViewController
tableVC.postKey = self.postKey
self.window?.rootViewController?.present(vc!, animated: true, completion: nil)
}
是否有可能做什麼我試圖?我試圖讓問題儘可能簡單,但讓我知道是否需要詳細說明。提前致謝。
爲什麼要那樣做?爲什麼不''self.navigationController?.pushViewController(vc,animated:false)'?或者爲什麼不直接使用segue? – Paulw11
@ Paulw11我無法使用push,因爲「self」是一個collectionviewcell,所以我僅限於顯示另一個視圖控制器的選項。而且我不確定segue如何幫助我顯示視圖控制器。 – dombad
好的,如果'self'是一個單元格,那麼你應該使用委託和按鈕點擊事件到正確的視圖控制器,以便它可以被處理。基本方法[這裏](https://stackoverflow.com/questions/28659845/swift-how-to-get-the-indexpath-row-when-a-button-in-a-cell-is-taped/38941510# 38941510)。顯示視圖控制器是segues所做的。 – Paulw11