我的应用程序的一个规格是,在点击tableView单元格时,用户将被重定向到与单元格关联的网站.这是代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let url = NSURL(string: appdelegate.studentInfo[indexPath.row].url) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
UIApplication.sharedApplication().openURL(url)
}
else {
let alert = UIAlertController(title: "Invalid URL", message: "Cannot open URL because it is invalid.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
在我第一次点击时,URL就像它应该的那样打开.但是,从Safari返回应用程序并触摸另一个单元格会导致以下错误,尽管该应用程序仍然可以正常工作:
快照未呈现的视图会导致空快照.确保在屏幕更新后快照或快照之前至少渲染了一次视图.
有什么办法可以避免这个错误吗?或者这是一个错误?
我已经尝试过dispatch_async块,但它没有解决问题.