我正在尝试通过按下“删除数据”按钮来发出警报。我的按钮位于导航 Controller 内的 View 中。这是我当前的代码
class SomeViewController: UIViewController {
@IBAction func deleteData(sender: UIButton) {
let alert = UIAlertController(title: "delete Data", message: "Do you want to delete the data", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default, handler: nil))
alert.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.Default, handler: nil))
}
}
但是给我以下错误:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
最佳答案
您已经创建了警报 View Controller ,但您仍然需要展示它:
self.presentViewController(alert, animated: true, completion: nil)
您可以在 appcoda.com 上阅读有关该主题的文章
关于swift - 我如何让这个 UIAlert 出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34926852/