ios - SDWebImage 使用 Swift 在 CellView 中将图像设置为 UIButton
问题描述
您好我正在使用 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
}
推荐阅读
- python - 从本地数据集中为 CNN 创建 TensorFlow 数据集
- google-cloud-platform - 403 请求的身份验证范围不足。使用应用程序默认凭据向谷歌云 NLP API 发出请求时
- c# - MVC 5 在主实体创建期间创建外键实体
- android - 如何在布局上放置方形广告
- laravel - Laravel cName SSL 证书
- jmeter - Json 提取唯一数据 - Jmeter
- java - How to pass variable from different class to the main class
- javascript - How can I collect data from multiple HTML checkboxes and input that data into a google sheet?
- mysql - How to do audit when using Spring batch as ETL
- r - Create multiple columns in data.table with `:=` without colnames