2014-02-26 81 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上,也可以爲我工作。

相關問題