首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SDWebImage使用Swift在CellView中将图像设置为UIButton

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

Stack Overflow用户
提问于 2019-06-16 12:47:45
回答 1查看 1.1K关注 0票数 1

您好,我正在使用SDWebImage在Xcode10.2.1中将图像设置为按钮。

我正在尝试以下方法

代码语言:javascript
复制
import SDWebImage

cell.bProfileImage.sd_setImage(with:URL(string:
individualChatsListArray[indexPath.row].profile_image), forState:.normal)

但是我得到了以下错误

代码语言:javascript
复制
Value of optional type 'UIButton?' must be unwrapped to refer to member
 'sd_setImage' of wrapped base type 'UIButton'

在nib文件中,这些项按如下方式链接和声明

代码语言:javascript
复制
@IBOutlet weak var bProfileImage: UIButton!


@IBAction func bProfileImage(_ sender: Any) {

    print("touch kia")

}

我试过了

代码语言:javascript
复制
cell.bProfileImage?.sd_setImage(with:URL(string:
individualChatsListArray[indexPath.row].profile_image), forState:.normal)

但随后会得到以下错误

代码语言:javascript
复制
Ambiguous reference to member 'bProfileImage'

如您所见,我是xcode/swift的新手

下面的代码没有给出任何错误,但也没有加载图像

代码语言:javascript
复制
cell.bProfileImage.sd_setBackgroundImage(with: URL(string:
individualChatsListArray[indexPath.row].profile_image), for:
UIControl.State.normal) { (image, error, cache, url) in }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-16 13:21:20

下面的代码运行得很完美。

代码语言:javascript
复制
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

}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56616154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档