iOS开发Receiver type 'AnswerButton' for instance message is a forward declaration解决

问题出现场景:

我在自定义cell的时候,在cell的.h文件中@class AnswerButton 并property了AnswerButton的属性,然后在cell.m文件内导入AnswerButton.h文件。

#import <UIKit/UIKit.h>

@class AnswerButton;

@interface EncryptedCollectionViewCell : UICollectionViewCell

@property (nonatomic, strong) AnswerButton *answerButton; // 选项

@end

===================在这之前都是没问题的

当我在控制器中UICollectionView的代理创建cell并想要修改cell的answerButton的title属性时,发现没有方法提示,直接手写后运行就会报错Receiver type 'AnswerButton' for instance message is a forward declaration。

===================解决

在cell.h中导入AnswerButton.h文件

扫描二维码关注公众号,回复: 2770548 查看本文章

===================原因

ARC要求完整的前向引用,也就是说在MRC时代可能仅仅须要在.h中申明@class就能够,可是在ARC中假设调用某个子类中未覆盖的父类中的方法的话。必须对父类.h引用,否则无法编译

猜你喜欢

转载自blog.csdn.net/ljw2017/article/details/81558200