【发布时间】:2016-01-08 04:56:44
【问题描述】:
我有一个带有项目集合视图的屏幕。如果用户没有选择任何东西,我希望弹出一个警报,提示他们选择一些东西。如果他们选择了什么,我想弹出一个警报,询问他们是否准备好继续前进?下面是我的代码:
if (isSelected) {
// create the alert
let alert = UIAlertController(title: "Create", message: "Make sure to select at least one item.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: { action in
alert.dismissViewControllerAnimated(true, completion: nil)
}))
self.presentViewController(alert, animated: true, completion: nil)
} else {
let alert2 = UIAlertController(title: "Move on", message: "Are you ready to move on?", preferredStyle: UIAlertControllerStyle.Alert)
alert2.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default, handler: { action in
self.performSegue to next screen
}))
n.addAction(UIAlertAction(title: "No", style: UIAlertActionStyle.Cancel, handler: { action in
}))
}
代码似乎没问题,但我收到以下错误:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
这似乎应该很容易工作并且是一件很常见的事情,但是没有在线解决这个问题。任何帮助/指导将不胜感激。
【问题讨论】:
标签: ios swift uiviewcontroller swift2 uialertcontroller