创建 UIAlertController 而不显示它会产生警告 [英] Creating UIAlertController without presenting it produces warning
本文介绍了创建 UIAlertController 而不显示它会产生警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当创建一个 UIAlertController
而不显示它时,控制台会打印警告.为什么会这样?
override func viewDidLoad() {super.viewDidLoad()让 _ = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)}
<块引用>
不允许在解除分配时尝试加载视图控制器的视图,这可能会导致未定义的行为
<小时>
忽略此警告是否安全?如果 UIAlertController
已经创建并且我决定不展示/使用它,我该怎么办?
解决方案
尝试在 viewDidAppear 中编写代码它可能会解决您的问题
override func viewDidAppear(animated: Bool) {super.viewDidAppear(true)让 alertController = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)}
When creating a UIAlertController
without presenting it, a warning is printed in the console. Why is this so?
override func viewDidLoad() {
super.viewDidLoad()
let _ = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)
}
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
Edit:
Is this warning safe to ignore? If the UIAlertController
is already created and I decide to not present/use it what should I do?
解决方案
Try to Write code in viewDidAppear it may solver your problem
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
let alertController = UIAlertController(title: "title", message: "message", preferredStyle: .Alert)
}
这篇关于创建 UIAlertController 而不显示它会产生警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文