代码之家  ›  专栏  ›  技术社区  ›  rma

翠鸟:“setBackgroundImage(with:for:placeholder:options:progressBlock:completionHandler:)的用法不明确”

  •  0
  • rma  · 技术社区  · 6 年前

    模糊使用

    这个表达有歧义吗?我看了KF文档,我想这就是你所说的。

    var options: KingfisherOptionsInfo = []
    options.append(.forceRefresh)
    button.kf.setBackgroundImage(with: URL(string: picture), for: .normal, placeholder: nil, options: options, progressBlock: nil, completionHandler: nil)
    
    1 回复  |  直到 6 年前
        1
  •  4
  •   M Reza    4 年前

    该错误是因为您需要处理 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
        }
    }
    
        2
  •  2
  •   Prasad Nesargi    5 年前

    我也有同样的问题,我只是通过删除函数调用中的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"))
    
        3
  •  1
  •   Bijender Singh Shekhawat    4 年前

    斯威夫特5号

    用这个替换你的线路。

    videoImageView.kf.setImage(with: resource, placeholder: nil, options: [.transition(.fade(0)), .processor(p)], progressBlock: nil) { (result) in
                    
    }
    
        4
  •  0
  •   Yodagama    4 年前

    我通过剥离未使用参数的函数调用(我们传递 nil )进口翠鸟。

    第一步 import Kingfisher

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

        5
  •  0
  •   Vishal Shelake    3 年前

    这对我来说是非常基本的修复,使用 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
                ])