自定义的UITableViewCell NSUnknownKeyException

问题描述:

- (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

该错误表示您已将某些东西连接到您的笔尖上的日期称为日期的插座,但该插座不存在。你在哪里申报日期?

+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

连接TododTableViewController XIB中的所有插座(特别是视图插座),然后再次运行。

  1. 将文件所有者的​​设置为UITableViewCell
  2. 将单元格的​​设置为您的自定义表格视图单元格类别myCustomCell
  3. 将您的UIlabel输出为myCustomCell.h
+0

谢谢,这条评论救了我! – Joshua 2016-08-17 07:49:39