问题
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 running on 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)
}
}
回答1:
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.
来源:https://stackoverflow.com/questions/57509557/xcode-11-beta-5-ui-freezes-when-adding-textfields-into-uialertcontroller