gpt4 book ai didi

ios - 无法将两个 AlertController 放在同一个 VC 上

转载 作者:行者123 更新时间:2023-11-28 11:11:36 24 4
gpt4 key购买 nike

我有一个带有项目 Collection View 的屏幕。如果用户没有选择任何东西,我想弹出一个警告,提示他们选择一些东西。如果他们选择了某些东西,我想弹出一个警报,询问他们是否准备好继续前进?下面是我的代码:

   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

这看起来应该很容易工作并且很常见,但是这个问题没有在线解决方案。非常感谢任何帮助/指导。

最佳答案

您错过了展示alert2

 self.presentViewController(alert2, animated: true, completion: nil)

添加它,它将正常工作。

关于ios - 无法将两个 AlertController 放在同一个 VC 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34669782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com