【发布时间】:2017-01-13 22:44:43
【问题描述】:
我正在使用警报控制器在 catch 块中显示错误。但是,在它自行消失之前,用户几乎看不到它。我究竟做错了什么?这是我的代码。
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if viewController is CancelInspectionViewController {
persistentContainer.viewContext.rollback()
self.dismiss(animated: true, completion: nil)
return false
} else if viewController is SubmitInspectionViewController {
do {
try persistentContainer.viewContext.save()
self.dismiss(animated: true, completion: nil)
} catch {
_alertController = UIAlertController(title: "Error Saving", message: error.localizedDescription, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
_alertController.addAction(defaultAction)
present(_alertController, animated:true, completion: {
self.dismiss(animated: true, completion: nil)
})
}
【问题讨论】:
标签: ios swift controller alert uialertcontroller