ios - 点击单元格时尝试显示不在窗口层次结构中的 View

标签 ios swift swift3

我目前正在开发一个带有 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/

相关文章:

ios - 如何根据TimeWise对数组进行排序?

javascript - React Native IOS 生产版本 : RCTFatalException crash and SocketProtocolError YellowBox

ios - Swift - 如何更改 accessoryType (disclosureIndicator) 的颜色?

Swift 枚举大小写访问级别

ios - 无法调用非函数类型 SKShapeNode 的值

javascript - 如何在WKWebView中调用带参数/不带参数的JavaScript函数?

ios - 其中一些带有 UIImageView 的 UITableViewCell

ios - 从应用程序委托(delegate)中关闭模态视图的最佳方法

ios - 仅适用于 iPhone x 的 AVPlayer 全屏问题

ios - 扩展符合 NSFetchRequestResult 的协议(protocol)