Mayank Kumar Mayank Kumar - 8 months ago 592
iOS Question

Swift: Getting 'Snapshotting a view that has not been rendered..' error when trying to open a URL in safari from my app

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)
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.


It might not be the same problem as me, but i just solved the same warning in my logs.

I'm showing an UIAlertController as an actionSheet popover on an ipad, and i had exactly the same warning 8 times in a row every time i tried to show the alertController.

To make the warning disappear all i had to do was to layout the alertController view as in the following code.

    let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)


    alertController.view.layoutIfNeeded() //avoid Snapshotting error
    self.presentViewController(alertController, animated: true, completion: nil)

I hope this helps you or any other person having the same warning.