ios - 自定义框架内的图像设置
问题描述
我正在尝试在我的自定义框架中设置图像,我正在使用以下方法来设置它。它无处不在,但不适用于我的习惯UITableViewCell
。
self.imageView.image = UIImage(named:"image",in: Bundle(for: type(of: self)), compatibleWith: nil)
我得到的错误:
无法调用非函数类型“NSInteger”(又名“Int”)的值
为什么它在 UITableViewCell 中不起作用。
解决方案
其实我已经自己解决了。
而不是这样调用。
self.imageView.image = UIImage(named:"image",in: Bundle(for: type(of: self)), compatibleWith: nil)
将其更改为:
self.imageView.image = UIImage(named:"image",in: Bundle(for: MyCustomCell.self), compatibleWith: nil)
这是有效的。
推荐阅读
- reactjs - API 响应在使用时未定义,但在 console.log() 时未定义
- python - 如何在样式化的 QFrame 中设置 QWidget 的背景样式?
- javascript - 如何使用 NextJS 预渲染解决“无法读取未定义的属性 'title'”?
- amazon-cloudformation - CloudFormation 的托管区域 ID
- android - 为什么更改默认应用程序名称在使用颤振构建的 android productFlavors 中不起作用
- r - 如何找到文件在容器内的位置?
- javascript - 根据api更改切换主路径
- ios - 程序化导航 SwiftUI:重新选择和选择屏幕外链接的问题
- angular - 工具提示中的角度 Highchart 多个值
- alert - 当最后价格高于 5ma 10% 时如何设置警报?