gpt4 book ai didi

ios - 翠鸟: 'setBackgroundImage(with:for:placeholder:options:progressBlock:completionHandler:)' 的使用不明确

转载 作者:搜寻专家 更新时间:2023-11-01 06:26:19 25 4
gpt4 key购买 nike

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

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

关于ios - 翠鸟: 'setBackgroundImage(with:for:placeholder:options:progressBlock:completionHandler:)' 的使用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54047903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com