我读过几个类似的问题,但没有一个能为我工作。好吧,我试图在列表上显示不同的图像并将这些图像保存在缓存中。我在iconView.sd电话上收到错误。
>>> addr = IPNetwork("10.0.0.0/24")
>>> addr
IPNetwork('10.0.0.0/24')
>>> mask = addr.prefixlen
>>> intip = IPNetwork(addr[-3])
>>> intip
IPNetwork('10.0.0.253/32')
>>>
>>> intip.prefixlen = mask
>>> intip
IPNetwork('10.0.0.253/24')
>>>
错误: TableViewCell.swift:22:26:无法调用' sd_setImageWithURL' 使用类型'的参数列表(NSURL?,placeholderImage:UIImage?, 完成:(UIImage!,NSError!,SDImageCacheType,NSURL!) - > ())'
列表中的图标(日志):
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
}
}
答案 0 :(得分:1)
问题可能是因为使用了旧的NS-Types,它在Swift3中被替换并且现在自动被Swift3映射到新的数据类型。
iconView.sd_setImage(with: URL(string: item!.icon),
placeholderImage: UIImage(named: "placeholder.png"),
options: .highPriority) { image, error, cacheType, imageURL in
}
答案 1 :(得分:1)
这对我有用。记得添加选项:这样的参数。
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
})