繁体   English   中英

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

[英]SDWebImage Set Image To UIButton in CellView Using Swift

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

以下是完美的工作。

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM