[英]SDWebImage Set Image To UIButton in CellView Using Swift
Hi I am using SDWebImage to set image to a button in xcode 10.2.1. 嗨我正在使用SDWebImage将图像设置为xcode 10.2.1中的按钮。
I am trying the following 我正在尝试以下方面
import SDWebImage
cell.bProfileImage.sd_setImage(with:URL(string:
individualChatsListArray[indexPath.row].profile_image), forState:.normal)
But I am getting the following error 但是我收到以下错误
Value of optional type 'UIButton?' must be unwrapped to refer to member
'sd_setImage' of wrapped base type 'UIButton'
In the nib file the items are linked and declared as per below 在nib文件中,项目链接并按以下方式声明
@IBOutlet weak var bProfileImage: UIButton!
@IBAction func bProfileImage(_ sender: Any) {
print("touch kia")
}
I have tried 我努力了
cell.bProfileImage?.sd_setImage(with:URL(string:
individualChatsListArray[indexPath.row].profile_image), forState:.normal)
But then getting the following error 但后来得到以下错误
Ambiguous reference to member 'bProfileImage'
As you can see I am new to xcode/swift 如你所见,我是xcode / swift的新手
The following is not giving any error but is also not loading the image 以下内容未给出任何错误,但也未加载图像
cell.bProfileImage.sd_setBackgroundImage(with: URL(string:
individualChatsListArray[indexPath.row].profile_image), for:
UIControl.State.normal) { (image, error, cache, url) in }
The following is working perfectly. 以下是完美的工作。
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.