我目前正在开发一个带有 UITableViewController 的应用程序。这个想法是,当点击一个单元格时,会弹出一个信息页面,显示有关它的一些信息。因此,当点击时,我尝试在另一个类中呈现另一个 ViewController。但是,出现了警告,我不知道为什么。
我尝试在 Stackoverflow 和其他网站上查看与我类似的问题,但它们对我来说没有多大意义。谁能解释一下这个警告背后的问题以及如何解决它?
我的一些代码:
override func tableView(_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath) {
print("showing item info")
let cell = tableView.cellForRow(at: indexPath)
currentInfo = (cell?.textLabel?.text)!
currentDes = descriptions[indexPath.row]
currentBool = itemBools[indexPath.row]
currentIndexPath = indexPath
showInfo()
}
func showInfo() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "ShowInfoViewController") as! ShowInfoViewController
self.present(vc, animated: true, completion: nil)
}
警告消息是:
Attempt to present <Things_to_Do.ShowInfoViewController: 0x100b2fe20> on <Things_to_Do.TableViewController: 0x100b05eb0> whose view is not in the window hierarchy!
最佳答案
尝试添加演示风格
swift 2
vc.modalPresentationStyle = .FormSheet
vc.modalTransitionStyle = .CoverVertical
关于ios - 点击单元格时尝试显示不在窗口层次结构中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39642894/