One of the specifications of my app is that on tapping a tableView cell, the user will be redirected to the website associated with the cell. Here is the code:
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)
}
}
On my first tap, the URL opens like it is supposed to. However, returning to the app from Safari and touching another cell results in the following error, although the app still works like it is supposed to:
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
Is there any way to avoid this error? Or is this a bug?
I have experimented with dispatch_async blocks but it did not solve the problem.
Aucun commentaire:
Enregistrer un commentaire