[英]How to dismiss an UIAlertController with no actions in SWIFT?
I display an UIAlertController when my image is downloading. 我的图像下载时显示UIAlertController。 When the downloading is finished, I want to push a view controller.
下载完成后,我想推送一个视图控制器。 I have an error in the console, because I don't dismiss the alert controller :
我在控制台中有错误,因为我没有关闭警报控制器:
pushViewController:animated: called on <UINavigationController 0x7fb190c6ee00> while an existing transition or presentation is occurring; the navigation stack will not be updated.
In my main view controller, when the downloading is finished, I push another view : 在我的主视图控制器中,当下载完成时,我推送另一个视图:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//....
var alert = UIAlertController(title: "Alert", message: text, preferredStyle: UIAlertControllerStyle.Alert)
self.presentViewController(alert, animated: true, completion: nil)
dispatch_async(dispatch_get_main_queue(), {
if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
self.performSegueWithIdentifier("postview", sender: self)
}
})
}
I tried wit dismissViewControllerAnimated but I have exactly the same error : 我尝试过dismissViewControllerAnimated,但我有完全相同的错误:
dispatch_async(dispatch_get_main_queue(), {
if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
alert.dismissViewControllerAnimated(true, completion: nil)
self.performSegueWithIdentifier("postview", sender: self)
}
})
You should not call performSegueWithIdentifier
before the previous view controller has been dismissed. 在解除上一个视图控制器之前,不应调用
performSegueWithIdentifier
。 To time this correctly, do it from the completion handler: 要正确计时,请从完成处理程序执行此操作:
dispatch_async(dispatch_get_main_queue(), {
if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
alert.dismissViewControllerAnimated(true, completion: {
self.performSegueWithIdentifier("postview", sender: self)
})
}
})
Now the call to perform segue would not start until the dismissal is over, preventing the error that you see. 现在执行segue的调用在解雇结束之前不会启动,从而防止您看到的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.