ios - SDWebImage 使用 Swift 将图像设置为 CellView 中的 UIButton

标签 ios swift sdwebimage

您好,我正在使用 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

}

关于ios - SDWebImage 使用 Swift 将图像设置为 CellView 中的 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56616154/

相关文章:

ios - 在 iOS 中跨应用程序(后台/前台或分屏多任务处理)共享 UDP 数据

ios - 如何快速将本地 JSON 文件加载到 uitableview 中?

ios - 监听队列中请求的最佳服务架构(基于队列的负载均衡)?

ios - 访问 obj 作为属性与方法参数(样式首选项)

swift - 理解 Swift 中的单例

ios - Firestore 离线未更新

ios - 如何在 ios 中正确缓存图像

ios - 如何获取缓存图像 SDWebImage 的数据

ios - SDWebImage 检查图像是否使用 Swift 缓存 : Ambiguous Reference

objective-c - iOS - 旋转时 View 无法在 iPad 中正确加载