gpt4 book ai didi

ios - 无法在 Swift 中的 UITableViewController 中呈现 UIAlertController

转载 作者:可可西里 更新时间:2023-11-01 01:25:37 25 4
gpt4 key购买 nike

我有一个 UIAlertController,我想在 UITableViewController 中显示它。但是,当我运行代码时,出现以下错误:

Warning: Attempt to present on whose view is not in the window hierarchy!

我的代码似乎反射(reflect)了 answer 中的建议.我做错了什么?

override func viewDidLoad() {
super.viewDidLoad()

// Check for force touch feature, and add force touch/previewing capability.
if traitCollection.forceTouchCapability == .available {
registerForPreviewing(with: self, sourceView: view)
}
else {
// Create an alert to display to the user.
alertController = UIAlertController(title: "3D Touch Not Available", message: "Unsupported device.", preferredStyle: .alert)
self.present(alertController!, animated: false, completion: nil)
}

最佳答案

假设,在 viewDidLoad 中,您仍然没有窗口层次结构中的 View ,如消息中所述。尝试将代码移至 viewDidAppear

关于ios - 无法在 Swift 中的 UITableViewController 中呈现 UIAlertController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41738176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com