ios – Swift:尝试在我的应用程序中在safari中打开一个URL时,获取“快照没有被渲染的视图..”错误

我的应用程序的一个规格是在点击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)
    } 
}

在我的第一个水龙头,网址打开像它应该是.但是,从Safari返回应用程序并触摸另一个单元格会导致以下错误,尽管该应用仍然按照以下原则:

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.

有没有办法避免这个错误?还是这个bug?

我已经尝试了dispatch_async块,但没有解决问题.

解决方法

这可能不是我一样的问题,但是我刚刚在我的日志中解决了同样的警告.

我在ipad上显示一个UIAlertController作为一个actionSheet popover,每次我试图显示alertController时,我都有8次完全相同的警告.

要使警告消失,我只需要像下面的代码一样布置alertController视图.

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

    ...            

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

我希望这可以帮助你或任何其他人有同样的警告.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...