setValue:forUndefinedKey:]:此类不是密钥值编码兼容的密钥使用UICollectionView

时间:2015-03-06 12:13:56

标签: objective-c uicollectionview

我有一个UICollectionView填充了具有自定义类的单元格,每个单元格都有3个标签图像,我刚添加了一个按钮,在添加按钮之前一切正常,现在我添加了按钮并将其连接到自定义单元格类(我还连接了标签和图像)填充UICollectionView时应用程序崩溃。 在连接检查器上,按钮只有将其连接到自定义单元类的Outlet(就像其他元素一样)所以为什么应用程序崩溃了? 这是我的头文件:

#import <UIKit/UIKit.h>


@interface CollectionViewCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIButton *TestButton; //this one is the button that causes the crash
@property (weak, nonatomic) IBOutlet UILabel *titleP;
@property (weak, nonatomic) IBOutlet UILabel *price;
@property (weak, nonatomic) IBOutlet UILabel *codeP;
@property (weak, nonatomic) IBOutlet UIImageView *img;

@end

编辑: 我不知道StoryBoard发生了什么,但我只需要清理项目,一切正常,感谢大家的帮助。

2 个答案:

答案 0 :(得分:3)

通常当我收到此错误时,这是​​因为我在代码中重命名了一个插座但没有正确更新故事板。如果您选择了故事板和连接检查器,您可能会看到其中一个连接!那应该是你的罪犯。

我希望有所帮助。

enter image description here

答案 1 :(得分:0)

根据我的经验,这会发生:

  1. right clicking on the name of the variable/function时,我没有使用refactor重命名了IBOutlet / IBAction
  2. 我已经从代码中删除了IBOutlet / IBAction,而没有从connection inspector中删除连接。

因此,请确保检查连接检查器中是否有yellow triangle的已重命名/已删除的变量或函数。

相关问题