【问题标题】:setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Using UICollectionViewsetValue:forUndefinedKey:]: 这个类对于键使用 UICollectionView 不是键值编码兼容的
【发布时间】:2015-05-08 01:05:45
【问题描述】:

我有一个 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 发生了什么,但我只需要清理项目,一切正常,感谢大家的帮助。

【问题讨论】:

  • 显示整个错误信息。
  • 还有钥匙。和代码。真的是 TestButton 还是 testButton?

标签: objective-c uicollectionview


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

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

    希望对你有帮助。

    【讨论】:

    • 我只需要清理项目,不知道为什么但它工作了
    猜你喜欢
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 2014-01-12
    • 2017-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    相关资源
    最近更新 更多