【问题标题】:Cannot invoke call from SDWebImage无法从 SDWebImage 调用调用
【发布时间】:2017-02-02 13:00:07
【问题描述】:

我已经阅读了几个类似的问题,但没有一个对我有用。好吧,我正在尝试在列表中显示不同的图像并将这些图像保存在缓存中。我在 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
}

}

错误:TableViewCell.swift:22:26:无法调用“sd_setImageWithURL” 带有类型为 '(NSURL?, placeholderImage: UIImage?, 完成:(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")...

【问题讨论】:

    标签: ios swift closures sdwebimage


    【解决方案1】:

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

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

    【讨论】:

    • 现在我收到错误:'sd_setImage' 的模糊使用。
    • 刚刚尝试过并且体验相同,即使我在编辑的答案中正确指定了类型。只有当我添加 options: 参数时它才对我有用。
    • 好吧。非常感谢。在哪里添加此选项:参数如果我可以问?
    • 我编辑了我的答案,我将如何编写它以及我如何在 xcode 中检查它。
    • 是的,它也有效。感谢您的输入。你忘了完成:调用选项后:highPriority
    【解决方案2】:

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

    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
                })
    

    【讨论】:

      猜你喜欢
      • 2016-05-04
      • 1970-01-01
      • 2017-10-07
      • 1970-01-01
      • 2011-09-21
      • 2016-01-13
      • 2012-01-08
      • 1970-01-01
      • 2016-08-09
      相关资源
      最近更新 更多