iOS6崩溃:此类不是密钥编码兼容密钥
问题描述:
我在iOS6设备上运行时遇到崩溃,但不是iOS 7设备时崩溃。我有一个自定义UITableViewCell
与xib LanguageCell.xib。它有2个标签,一个按钮和一个视图。我有一个类LanguageCell在那里我有4个IBOutlets:iOS6崩溃:此类不是密钥编码兼容密钥
@interface LanguageCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *titleLbl;
@property (strong, nonatomic) IBOutlet UIButton *buyButton;
@property (strong, nonatomic) IBOutlet UILabel *saleLbl;
@property (strong, nonatomic) IBOutlet UIView *separatorLine;
我已经连接的所有4次到他们的属性,这样的连接面板看起来是这样的:
当我运行应用程序,加载此表时发生崩溃:
*** Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<LanguageCell 0x1f5160c0> setValue:forUndefinedKey:]: this class
is not key value coding-compliant for the key buyButton.'
为什么我在iOS6上遇到这个问题,但不是在iOS7上?
编辑: 我要补充的是,自定义类设置正确的厦门国际银行
编辑2: 当我清除所有的IB连接和运行代码时,线if ([currentObject isKindOfClass:[LanguageCell class]])
返回false时,它应该是真实的,从而cell
仍然nil
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
LanguageCell *cell = (LanguageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"LanguageCell" owner:nil options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[LanguageCell class]])
{
cell = (LanguageCell *)currentObject;
break;
}
}
}
我在我的应用程序中为3个其他表使用相同的确切代码,它工作得很好。我不明白为什么这个会给我带来麻烦。
答
我有完全相同的问题。这通常只会在Interface Builder
内连接一个不存在的方法时发生。
我也使用了相同的类名。更改名称后,即使在iOS 6.0
上,也可以为我工作。
您是否尝试清洁该项目? 'Shift + CMD + K' – hgwhittle
是的。清理,清理生成文件夹,删除派生数据,关闭Xcode,从手机中删除应用程序等等。没有任何工作:( –
故事板有时可能会损坏,请尝试清除IB中的连接,保存并重新创建它 –