我的应用程序的一个规范是,点击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)
}
}
在我第一次点击时,URL会像预期的那样打开.然而,从Safari返回应用程序并touch 另一个单元格会导致以下错误,尽管该应用程序仍能正常工作:
对尚未渲染的视图进行快照会导致空视图
有没有办法避免这个错误?还是这是一只虫子?
我曾try 过dispatch_async块,但没有解决问题.