我试图在嵌入在NavigationController中的ViewController之上呈现嵌入在NavigationController中的tableViewController。
我不断收到错误:无法显示视图控制器,因为它不在窗口层次结构中。
简而言之,我试图允许用户点击帖子上的the number of likes
,然后将其定向到NavigationController中的嵌入式TableViewController,它无效。
出于某种原因,当我尝试点击相同的数字而不是当我从导航控制器执行此操作时,它会从标签栏控制器显示。单击相同编号的操作的代码如下所示,位于集合视图单元格swift文件中:
@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)
}
有可能做我正在尝试的事情吗?我试图让问题尽可能简单,但如果我需要详细说明,请告诉我。提前致谢。
答案 0 :(得分:0)
解决方案可能是用这个替换最后一行:
UIApplication.shared.keyWindow?.rootViewController?.present(vc!, animated: true, completion: nil)
有关更多信息和各种解决方案,您还可以查看thread