我有一段代码,在这里我提出了警告:
func arraysize() -> [Int]? {
let title = "Your file is empty"
let message = "Please refer to the instructions"
let okText = "OK"
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
let okayButton = UIAlertAction(title: okText, style: UIAlertActionStyle.Cancel, handler: nil)
alert.addAction(okayButton)
do{
....
if array?.isEmpty == true{
print("the array is empty")
presentViewController(alert, animated: true, completion: nil)
}
}
catch let error {
print(error)
}
return array
}但是我的警报没有显示出来。它曾经显示,尽管我没有更改任何代码,但它停止了对我的工作。有人能帮我明白我做错了什么吗?
我也收到了这样的警告:
16632:713433警告:尝试显示视图不在窗口层次结构中的UIAlertController!
会是这样吗?
发布于 2016-04-16 17:16:26
正如@rmaddy在评论中解释的那样,我的问题是,我试图从控制器中显示一个从未出现在实际屏幕上的警报。我通过从一个出现在屏幕上的控制器调用这个方法来修正这个问题,它成功了。
https://stackoverflow.com/questions/36666440
复制相似问题