2

我一直在尝试使用 Kingfisher 设置按钮的背景图像,但我得到了一个 swift 编译器错误:

'setBackgroundImage(with:for:placeholder:options:progressBlock:completionHandler:)' 的模糊使用

这个表达有什么歧义?我查看了 KF 文档,我认为这就是您所说的。

var options: KingfisherOptionsInfo = []
options.append(.forceRefresh)
button.kf.setBackgroundImage(with: URL(string: picture), for: .normal, placeholder: nil, options: options, progressBlock: nil, completionHandler: nil)
4

5 回答 5

5

该错误是因为您需要处理completionHandler而不是传递nil. 试试下面的代码:

button.kf.setBackgroundImage(with: URL(string: picture), for: .normal, placeholder: nil, options: options, progressBlock: nil) { result in
    // result is either a .success(RetrieveImageResult) or a .failure(KingfisherError)
    switch result {
    case .success(let value):
        // The image was set to image view:
        print(value.image)

        // From where the image was retrieved:
        // - .none - Just downloaded.
        // - .memory - Got from memory cache.
        // - .disk - Got from disk cache.
        print(value.cacheType)

        // The source object which contains information like `url`.
        print(value.source)

    case .failure(let error):
        print(error) // The error happens
    }
}
于 2019-01-05T04:37:23.203 回答
2

我有同样的问题,我通过删除函数调用中的 nil 参数来解决它。

imgBanner.kf.setImage(with: url , placeholder:#imageLiteral(resourceName: "landscape.png"), options: nil, progressBlock: nil, completionHandler: nil) 

 imgBanner.kf.setImage(with: url , placeholder:#imageLiteral(resourceName: "landscape.png"))
于 2019-10-24T06:33:56.887 回答
1

对于迅捷5

用这个替换你的行。

videoImageView.kf.setImage(with: resource, placeholder: nil, options: [.transition(.fade(0)), .processor(p)], progressBlock: nil) { (result) in
                
}
于 2020-07-15T19:57:21.750 回答
0

我通过剥离未使用参数的函数调用(我们传递的地方nil)并导入 Kingfisher 来解决它。

步骤 1import Kingfisher

步骤 2button.kf.setBackgroundImage(with: URL(string: urlString), for: .normal, options: options)

于 2020-07-30T05:46:03.450 回答
0

这对我来说非常基本的修复,使用URL(string: url)而不只是字符串urlXcode 所需的类型特定

cell.imgView.kf.setImage(
            with: URL(string: url),
            placeholder: UIImage(named: "dummyaadhar"),
            options: [
                .processor(processor),
                .scaleFactor(UIScreen.main.scale),
                .transition(.fade(1)),
                .cacheOriginalImage
            ])
于 2021-07-16T00:39:34.567 回答