【问题标题】:How to use UIImageView load() fuction with the completionHandler in swift如何在swift中使用带有completionHandler的UIImageView load()函数
【发布时间】:2016-01-12 19:31:56
【问题描述】:

我正在使用 url 加载图像,但想在加载图像时显示加载图标。我发现这个方法签名有一个我想使用但不知道如何使用 completionHandler 的 completionHandler。

UIImageView.load( URL: URLLiteralConvertible, placeholder: UIImage?, completionHandler (NSURL, UIImage?, NSError?, CacheType) -> ())

有人知道怎么称呼吗?谢谢!

我目前所拥有的

let imgUrl = NSURL(string: imgURL)

self.img.load(imgUrl!, placeholder: UIImage(named: "greySq.png"), completionHandler: { _ in

} //Throws a syntax error

【问题讨论】:

    标签: swift uiimageview completionhandler


    【解决方案1】:

    原来我不需要使用完成处理程序调用加载函数来获得我想要的东西。使用下面的变体给了我想要的结果。

    self.img.load(imgUrl!, placeholder: UIImage(named: "greySq.png")){ _ in                
        self.formView.spinner.stopAnimating() 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-17
      • 2021-04-26
      • 1970-01-01
      • 2015-11-12
      • 1970-01-01
      • 2020-05-03
      • 2017-04-30
      相关资源
      最近更新 更多