首页 > 解决方案 > 自定义框架内的图像设置

问题描述

我正在尝试在我的自定义框架中设置图像,我正在使用以下方法来设置它。它无处不在,但不适用于我的习惯UITableViewCell

self.imageView.image = UIImage(named:"image",in: Bundle(for: type(of: self)), compatibleWith: nil)

我得到的错误:

无法调用非函数类型“NSInteger”(又名“Int”)的值

为什么它在 UITableViewCell 中不起作用。

标签: iosswift

解决方案


其实我已经自己解决了。

而不是这样调用。

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)

这是有效的。


推荐阅读