翠鸟:'setBackgroundImage(with:for:placeholder:options:progressBlock:completionHandler:)' 的使用不明确
Kingfisher: Ambiguous use of 'setBackgroundImage(with:for:placeholder:options:progressBlock:completionHandler:)'
我一直在尝试使用 Kingfisher 设置按钮的背景图像,但我遇到了 swift 编译器错误:
Ambiguous use of
'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)
该错误是因为您需要处理 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
}
}
我有同样的问题,我通过删除函数调用中的 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"))
为swift5
用这个替换你的行。
videoImageView.kf.setImage(with: resource, placeholder: nil, options: [.transition(.fade(0)), .processor(p)], progressBlock: nil) { (result) in
}
我通过剥离未使用参数的函数调用(我们传递 nil
的地方)并导入 Kingfisher 来解决它。
步骤 1。 import Kingfisher
步骤 2。 button.kf.setBackgroundImage(with: URL(string: urlString), for: .normal, options: options)
这对我来说非常基本的修复,使用 URL(string: url)
而不仅仅是字符串 url
Xcode 需要特定类型
cell.imgView.kf.setImage(
with: URL(string: url),
placeholder: UIImage(named: "dummyaadhar"),
options: [
.processor(processor),
.scaleFactor(UIScreen.main.scale),
.transition(.fade(1)),
.cacheOriginalImage
])
我一直在尝试使用 Kingfisher 设置按钮的背景图像,但我遇到了 swift 编译器错误:
Ambiguous use of '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)
该错误是因为您需要处理 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
}
}
我有同样的问题,我通过删除函数调用中的 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"))
为swift5
用这个替换你的行。
videoImageView.kf.setImage(with: resource, placeholder: nil, options: [.transition(.fade(0)), .processor(p)], progressBlock: nil) { (result) in
}
我通过剥离未使用参数的函数调用(我们传递 nil
的地方)并导入 Kingfisher 来解决它。
步骤 1。 import Kingfisher
步骤 2。 button.kf.setBackgroundImage(with: URL(string: urlString), for: .normal, options: options)
这对我来说非常基本的修复,使用 URL(string: url)
而不仅仅是字符串 url
Xcode 需要特定类型
cell.imgView.kf.setImage(
with: URL(string: url),
placeholder: UIImage(named: "dummyaadhar"),
options: [
.processor(processor),
.scaleFactor(UIScreen.main.scale),
.transition(.fade(1)),
.cacheOriginalImage
])