【问题标题】:Loading images from URL via Kingfisher on iWatch takes a long time在 iWatch 上通过 Kingfisher 从 URL 加载图像需要很长时间
【发布时间】: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


【解决方案1】:

试试这个代码。它会起作用的。

   DispatchQueue.main.async(execute: {() -> Void in
                self.mainGroup.setBackgroundImage(image)
            })

【讨论】:

    猜你喜欢
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 2012-07-13
    • 2017-05-01
    • 2021-11-29
    相关资源
    最近更新 更多