2014-02-26 85 views
2

我在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次到他们的属性,这样的连接面板看起来是这样的:

enter image description here

当我运行应用程序,加载此表时发生崩溃:

*** 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上?

编辑: 我要补充的是,自定义类设置正确的厦门国际银行

enter image description here

编辑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个其他表使用相同的确切代码,它工作得很好。我不明白为什么这个会给我带来麻烦。

+1

您是否尝试清洁该项目? 'Shift + CMD + K' – hgwhittle

+0

是的。清理,清理生成文件夹,删除派生数据,关闭Xcode,从手机中删除应用程序等等。没有任何工作:( –

+0

故事板有时可能会损坏,请尝试清除IB中的连接,保存并重新创建它 –

回答

3

我有完全相同的问题。这通常只会在Interface Builder内连接一个不存在的方法时发生。

我也使用了相同的类名。更改名称后,即使在iOS 6.0上,也可以为我工作。

相关问题