swift - 当我尝试从 firebase 获取图像时,Tableview 崩溃
问题描述
我收到此错误。我还提供了一个屏幕截图,更详细地查看了我以前从未见过的错误
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“在从主线程访问布局引擎后,不得从后台线程对其进行修改。”
//MARK: EXPLANATION (your passing item in down below because this allows you to call whatever is in the item class)
func generateCellForITEMS(item : Item){
nameLabel.text = item.name
descriptionLabel.text = item.description
priceLabel.text = convertCurrency(item.price )
priceLabel.adjustsFontSizeToFitWidth = true // this will adjust the font of the label sizse to helpt it fit even with a large price
if item.imageLinks != nil && item.imageLinks.count > 0 {
downLoadImages(imageUrls: [item.imageLinks.first!]) { (images) in
self.ItemImageView.image = images.first as? UIImage
}
}
}
解决方案
正如错误提示的那样,您需要从主线程更新 UI:
downLoadImages(imageUrls: [item.imageLinks.first!]) { (images) in
DispatchQueue.main.async {
self.ItemImageView.image = images.first as? UIImage
}
}
推荐阅读
- java - 创建名为“passwordEncoder”的 bean 时出错:请求的 bean 当前正在创建中
- postgresql - 在 PostgreSQL 中将列的数据类型更改为整数(带有 n/a 的列)
- c - Lua如何将用户数据从元表__index放入C闭包?
- javascript - 在 Dropzone JS 中选择文件后立即更新 UI
- python - 是否有任何函数可以将 python 代码转换为 MIPS?
- cookies - 为什么每个网站编码人员都不使用 DNT?
- python-3.x - TFS REST API System.IterationPath 返回错误
- c# - 请求中的重定向 URI https://localhost:44322/domain.com 与授权给 OAuth 客户端的 URI 不匹配
- vue.js - Vue 监视待处理的 http 请求
- c# - DirectoryInfo.EnumerateDirectories 仅可访问的文件夹和未隐藏的文件夹