无法调用来自 SDWebImage 的调用

Cannot invoke call from SDWebImage

我读过几个类似的问题,但其中 none 对我有用。好吧,我正在尝试在列表中显示不同的图像并将这些图像保存在缓存中。我在 iconView.sd 调用时遇到错误。

import UIKit
import SDWebImage

class TableViewCell: UITableViewCell {

var item: ItemRealm? {
    didSet {
        if item == nil {
            iconView.image = nil
            itemTitleLabel.text = "Test"
            itemDescLabel.text = "Some description"
        } else {
            // TODO: Implement item sets
            iconView.sd_setImage(with: NSURL(string: (item?.icon)!),
                                 placeholderImage: UIImage(named: "placeholder.png"), 
                                 completed: { (image: UIImage!, error: NSError!, cachetype: SDImageCacheType, imageURL: NSURL!) in

                                            })
            itemTitleLabel.text = item?.name
            itemDescLabel.text = item?.desc

        }
    }
}

@IBOutlet weak var iconView: UIImageView!
@IBOutlet weak var itemTitleLabel: UILabel!
@IBOutlet weak var itemDescLabel: UILabel!

override func awakeFromNib() {
    super.awakeFromNib()
    iconView.layer.cornerRadius = 4
}

override func prepareForReuse() {
    super.prepareForReuse()
    self.item = nil
}

}

Error : TableViewCell.swift:22:26: Cannot invoke 'sd_setImageWithURL' with an argument list of type '(NSURL?, placeholderImage: UIImage?, completed: (UIImage!, NSError!, SDImageCacheType, NSURL!) -> ())'

列表中的图标(日志):

 ; icon: Optional("http://192.168.1.101:8080/api/items/0/icon.png")
 ; icon: Optional("http://192.168.1.101:8080/api/items/1/icon.png")...

问题可能是因为使用了旧的 NS-Types,它在 Swift3 中被替换并且现在被 Swift3 自动映射到新的数据类型。

iconView.sd_setImage(with: URL(string: item!.icon),
         placeholderImage: UIImage(named: "placeholder.png"),
                  options: .highPriority) { image, error, cacheType, imageURL in
}

这对我有用。记得添加选项:这样的参数。

iconView.sd_setImage(with: URL(string: item!.icon), placeholderImage: 
      UIImage(named: "placeholder.png"), options: SDWebImageOptions(), 
      completed: { (image: UIImage?, error: Error?, cachetype: SDImageCacheType,
     imageURL: URL?) in
            })