Swift 中 `setImageWith(_:placeholderImage:usingActivityIndi​​catorStyle:)` 的使用不明确 3

Ambiguous use of `setImageWith(_:placeholderImage:usingActivityIndicatorStyle:)` in Swift 3

此代码在 Swift 2.3 中运行良好,但当我升级到 Swift 3.0 时,编译器抱怨使用不明确。

imgProfilePhoto?.setImageWith((URL(string: profileurl)), placeholderImage: UIImage(named: "PatientDefaultProfilePic"), usingActivityIndicatorStyle:UIActivityIndicatorViewStyle.gray)

Swift 等效方法可替代 SDWebImage 中的此方法:

imgProfilePhoto?.sd_setImageWithIndicator(with: URL(string: profileurl), placeholderImage: UIImage(named: "PatientDefaultProfilePic"))

Swift 4

import SDWebImage
extension UIImageView {

@objc func setImageWithIndicator(urlStr: String?, placeholder: UIImage) {
    guard let _ = urlStr, let url = URL(string: urlStr!) else {
        image = placeholder
        return
    }
    sd_setIndicatorStyle(.gray)
    sd_addActivityIndicator()
    sd_setImage(with: url, placeholderImage: placeholder, options: .refreshCached, completed: nil)
}}

Swift 3

imageView.sd_setImage(with: URL(string: ""), placeholderImage: UIImage(named: ""))
imageView.setShowActivityIndicator(true)
imageView.setIndicatorStyle(.gray)

这条线对我也有用:

添加完成处理程序 nil。

imgView.setImageWith(imgUrl, completed: nil, usingActivityIndicatorStyle: .gray)