【问题标题】:SDWebImage Set Image To UIButton in CellView Using SwiftSDWebImage 使用 Swift 在 CellView 中将图像设置为 UIButton
【发布时间】:2019-06-16 04:47:44
【问题描述】:

您好,我正在使用 SDWebImage 将图像设置为 xcode 10.2.1 中的按钮。

我正在尝试以下方法

import SDWebImage

cell.bProfileImage.sd_setImage(with:URL(string:
individualChatsListArray[indexPath.row].profile_image), forState:.normal)

但我收到以下错误

Value of optional type 'UIButton?' must be unwrapped to refer to member
 'sd_setImage' of wrapped base type 'UIButton'

在 nib 文件中,项目被链接并如下声明

@IBOutlet weak var bProfileImage: UIButton!


@IBAction func bProfileImage(_ sender: Any) {

    print("touch kia")

}

我试过了

cell.bProfileImage?.sd_setImage(with:URL(string:
individualChatsListArray[indexPath.row].profile_image), forState:.normal)

但随后出现以下错误

Ambiguous reference to member 'bProfileImage'

如您所见,我是 xcode/swift 的新手

以下没有给出任何错误,但也没有加载图像

cell.bProfileImage.sd_setBackgroundImage(with: URL(string:
individualChatsListArray[indexPath.row].profile_image), for:
UIControl.State.normal) { (image, error, cache, url) in }

【问题讨论】:

    标签: ios swift sdwebimage


    【解决方案1】:

    以下工作完美。

    cell.bProfileImage.sd_setBackgroundImage(with: URL(string:
    individualChatsListArray[indexPath.row].profile_image), for:
    UIControl.State.normal, placeholderImage: UIImage(named:
    "default_profile"), options: SDWebImageOptions(rawValue: 0)) { (image,
    error, cache, url) in
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-01
      • 2014-10-20
      • 1970-01-01
      • 2017-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      相关资源
      最近更新 更多