Swift:尝试从我的应用中打开Safari浏览器中的URL时,出现“快照未呈现的视图快照.."错误 [英] Swift: Getting 'Snapshotting a view that has not been rendered..' error when trying to open a URL in safari from my app

查看:123
本文介绍了Swift:尝试从我的应用中打开Safari浏览器中的URL时,出现“快照未呈现的视图快照.."错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的规范之一是,在点击tableView单元格时,用户将被重定向到与该单元格关联的网站.这是代码:

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

第一次点击时,URL会像预期的那样打开.但是,从Safari返回该应用并触摸另一个单元格会导致以下错误,尽管该应用仍然可以像预期的那样工作:

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?

我已经尝试了dispatch_async块,但是并不能解决问题.

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.

我正在显示UIAlertController作为iPad上的actionSheet弹出窗口,并且每次尝试显示警报控制器时,我都连续8次收到完全相同的警告.

I'm showing a 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 alert controller.

要使警告消失,我所要做的就是按照以下代码布置警报控制器视图:

To make the warning disappear all I had to do was to layout the alert controller 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.

这篇关于Swift:尝试从我的应用中打开Safari浏览器中的URL时,出现“快照未呈现的视图快照.."错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆