【问题标题】:Custom UITableViewCell NSUnknownKeyException自定义 UITableViewCell NSUnknownKeyException
【发布时间】:2012-03-24 14:16:26
【问题描述】:
- (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;
 }

运行时:

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

还有一个例外: * 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合关键日期的键值编码。”

我不知道为什么会发生,所以请帮我解决这个问题,提前谢谢!

【问题讨论】:

标签: objective-c ios uitableview


【解决方案1】:

该错误表示您已将某些东西连接到笔尖中名为 date 的插座,但该插座不存在。你在哪里声明日期?

【讨论】:

  • data是自定义单元格的标签,我在TodoTableViewCellController.h中声明
  • 下一个问题,你在哪里调用loadNibNamed?
  • 是日期,现在我把它的名字改成dateLabel...查看nib文件,没有问题。
  • 我不明白“你在哪里调用 loadNibNamed”是什么意思?我在 cellForRowAtIndexPath 中调用了这个函数。我更改了名称,但同样的标题,“关键日期”
  • 好的,我犯了一个错误:dateLabel 连接到文件的所有者,它应该连接到 CellController!谢谢!
【解决方案2】:
  1. 将文件所有者的Custom Class 设置为UITableViewCell
  2. 将单元格的Custom Class 设置为您的自定义表格视图单元格类myCustomCell
  3. myCustomCell.h 中输出您的UIlabel

【讨论】:

  • 谢谢,这个 cmets 救了我!
  • 这是我的问题的答案。我已将文件所有者自定义类设置为我自己的类并将插座连接到该类。谢谢。
【解决方案3】:

在 TododTableViewController XIB 中连接所有的 outlet(尤其是 view outlet),然后再次运行。

【讨论】:

    猜你喜欢
    • 2015-11-13
    • 2012-10-05
    • 1970-01-01
    • 2013-08-29
    • 2011-01-29
    • 2015-02-05
    • 2013-06-10
    相关资源
    最近更新 更多