自定义的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:]:这类不是关键日期的关键值编码。“
我不知道为什么会发生,所以请帮助我,谢谢!
答
连接TododTableViewController XIB中的所有插座(特别是视图插座),然后再次运行。
答
- 将文件所有者的设置为
UITableViewCell
。 - 将单元格的设置为您的自定义表格视图单元格类别
myCustomCell
。 - 将您的
UIlabel
输出为myCustomCell.h
。
+0
谢谢,这条评论救了我! – Joshua 2016-08-17 07:49:39
[此类不是密钥的密钥值编码兼容密钥]的可能重复(http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant -for-the-key) – jtbandes 2015-08-01 19:18:02