2012-03-24 103 views
5
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *TodoListTableIdentifier = @"TodoListTableIdentifier"; 
    TodoTableViewCellController *cell = (TodoTableViewCellController *)[tableView dequeueReusableCellWithIdentifier:TodoListTableIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"TodoTableViewCellController" owner:self options:nil]; 
     cell=[nib objectAtIndex:0]; 
     [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; 
    } 
    Todo *todo = [self.allTodoArray objectAtIndex:[indexPath row]]; 


    cell.titleLabel.text = todo.fileTitle; 
    cell.money.text = [NSString stringWithFormat:@"Monei:%f",todo.amount]; 
    cell.name.text = todo.realName; 
    cell.date.text = todo.operateTime; 

    return cell; 
} 

運行時:自定義的UITableViewCell NSUnknownKeyException

NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"TodoTableViewCellController" owner:self options:nil]; 

,並有一個例外: *終止應用程序由於未捕獲的異常 'NSUnknownKeyException',原因:「[setValue方法:forUndefinedKey:]:這類不是關鍵日期的關鍵值編碼。「

我不知道爲什麼會發生,所以請幫助我,謝謝!

+0

[此類不是密鑰的密鑰值編碼兼容密鑰]的可能重複(http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant -for-the-key) – jtbandes 2015-08-01 19:18:02

回答

15

該錯誤表示您已將某些東西連接到您的筆尖上的日期稱爲日期的插座,但該插座不存在。你在哪裏申報日期?

+0

data是自定義單元格的標籤,我在TodoTableViewCellController.h中聲明它 – jxdwinter 2012-03-24 14:41:51

+0

它是數據還是日期? – borrrden 2012-03-24 14:44:39

+0

下一個問題,你在哪裏調用loadNibNamed? – borrrden 2012-03-24 14:45:46

2

連接TododTableViewController XIB中的所有插座(特別是視圖插座),然後再次運行。

1
  1. 將文件所有者的​​設置爲UITableViewCell
  2. 將單元格的​​設置爲您的自定義表格視圖單元格類別myCustomCell
  3. 將您的UIlabel輸出爲myCustomCell.h
+0

謝謝,這條評論救了我! – Joshua 2016-08-17 07:49:39