问题描述
当我将一个或多个 textField 添加到 UIAlertController 时,应用程序冻结,一旦我删除了 textFields,它就可以正常工作.
When I add one or more textField into UIAlertController the app freezes, once I deleted the textFields it works perfectly fine.
Xcode 11 beta 5 在 Mojave 10.14.6 上运行
@IBAction func addRecipeBtnHandler(_ sender: Any) {
let alert = UIAlertController(title: "Add new recipe", message: nil, preferredStyle: .alert)
alert.addTextField { textField in
textField.placeholder = "title"
}
alert.addTextField { textField in
textField.placeholder = "description"
}
let action = UIAlertAction(title: "Add", style: .default) { alertAction in
let title = alert.textFields?.first?.text ?? ""
let description = alert.textFields?.last?.text ?? ""
let recipe = Recipe(title: title, description: description)
self.recipes.append(recipe)
self.updateSnapshot()
}
alert.addAction(action)
DispatchQueue.main.async {
self.present(alert, animated: true)
}
}
推荐答案
我在使用 beta 6 时遇到了同样的问题.切换到新的模拟器(即我以前没有使用过的设备)暂时解决了这个问题.对我来说似乎是 Xcode 中的一个错误.硬件 > 擦除所有内容和设置也会暂时修复模拟器一段时间.一段时间后,该错误再次出现.
I had the same problem with beta 6. Switching to a new emulator (i.e. a device I hadn't used before) temporarily solved the problem. Seems like a bug in Xcode to me.Hardware > Erase all content and settings also temporarily fixes the emulator for a while. The bug then reappears after some time.
这篇关于Xcode 11 beta 5:将 textFields 添加到 UIAlertController 时 UI 冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!