我的应用程序的一个规格是在点击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?
解决方法
这可能不是我一样的问题,但是我刚刚在我的日志中解决了同样的警告.
我在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)
我希望这可以帮助你或任何其他人有同样的警告.