SDWebImage使用Swift将图像设置为CellView中的UIButton

时间:2019-06-16 04:47:44

标签: ios swift sdwebimage

嗨,我正在使用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 }

1 个答案:

答案 0 :(得分:0)

以下内容运行良好。

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

}