![](/img/trans.png)
[英]How to set default image when imageURL is empty using SDWebImage - Swift
[英]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.