Ios 无法在同一个VC上放置两个AlertController
我有一个屏幕,上面有项目的集合视图。如果用户没有选择任何内容,我希望弹出一个警报,提示他们选择某个内容。如果他们选择了什么,我希望弹出一个警报,询问他们是否准备好继续前进?下面是我的代码:Ios 无法在同一个VC上放置两个AlertController,ios,swift,uiviewcontroller,swift2,uialertcontroller,Ios,Swift,Uiviewcontroller,Swift2,Uialertcontroller,我有一个屏幕,上面有项目的集合视图。如果用户没有选择任何内容,我希望弹出一个警报,提示他们选择某个内容。如果他们选择了什么,我希望弹出一个警报,询问他们是否准备好继续前进?下面是我的代码: if (isSelected) { // create the alert let alert = UIAlertController(title: "Create", message: "Make sure to select at least one item.",
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
这看起来应该很容易工作,而且是一件很常见的事情,但是这个问题没有在线解决方案。任何帮助/指导都将不胜感激。您错过了演示警报2
self.presentViewController(alert2, animated: true, completion: nil)
加上这个,它就可以正常工作。您错过了演示警报2
self.presentViewController(alert2, animated: true, completion: nil)
加上它,它就可以正常工作。这一行不是必需的: alert.dismissViewControllerAnimated(真,完成:无) 还加
self.presentViewController(alert, animated: true, completion: nil)
在其他部分中。不需要此行: alert.dismissViewControllerAnimated(真,完成:无) 还加
self.presentViewController(alert, animated: true, completion: nil)
在其他部分