【发布时间】:2017-11-07 10:16:39
【问题描述】:
我正在开发具有 WKInterfaceTable 的 Watch 应用程序,并且在表格的每个单元格中,我必须从 URL 加载图像,
我使用Kingfisher 来加载这样的图像:
self.mainGroup.setBackgroundImage(defualt_Image) //placeholder image
if let placeUrl = URL(string: urlString) {
_ = KingfisherManager.shared.retrieveImage(with: placeUrl, options: nil, progressBlock: nil, completionHandler: { (image, error, cacheType, imageURL) in
if image != nil {
DispatchQueue.main.async {
self.mainGroup.setBackgroundImage(image)
}
}
})
}
这个代码在我建表时被调用。
问题是图片加载大约需要 20 秒,
我为这个问题搜索了很多,但没有有用的答案。
有人在 iWatch 上遇到过同样的问题吗?
请帮忙!
谢谢。
【问题讨论】:
-
retrieveImage 是一种异步方法。确保从主线程更新 UI
-
@LeoDabus 嗨,谢谢你的回答,我更新了我的代码,但不幸的是,没有发生任何变化,图像仍然需要很长时间才能加载,请检查我更新的代码
标签: swift watchkit watch kingfisher