SDWebImage使用Swift将图像设置为CellView中的UIButton [英] SDWebImage Set Image To UIButton in CellView Using Swift
本文介绍了SDWebImage使用Swift将图像设置为CellView中的UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用SDWebImage将图像设置为xcode 10.2.1中的按钮.
Hi I am using SDWebImage to set image to a button in 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文件中,各项均按照以下说明进行链接和声明
In the nib file the items are linked and declared as per below
@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的新手
As you can see I am new to 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 }
推荐答案
以下内容运行良好.
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
}
这篇关于SDWebImage使用Swift将图像设置为CellView中的UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文