rma*_*iar 2 ios swift kingfisher
我一直在尝试使用 Kingfisher 设置按钮的背景图像,但我收到了一个快速编译器错误:
'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)
Run Code Online (Sandbox Code Playgroud)
该错误是因为您需要处理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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3862 次 |
| 最近记录: |