6
- (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;
 }

when running :

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

and there is an exception: * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key date.'

I dont know why is happen , so please help me with this, thank you in advance!

jxdwinter
  • 2,339
  • 6
  • 36
  • 56
  • possible duplicate of [This class is not key value coding-compliant for the key](http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant-for-the-key) – jtbandes Aug 01 '15 at 19:18

3 Answers3

18

The error means that you have connected something to an outlet called date in your nib but that outlet does not exist. Where do you declare date?

borrrden
  • 33,256
  • 8
  • 74
  • 109
  • data is a label of the custom cell,and I declare it in the TodoTableViewCellController.h – jxdwinter Mar 24 '12 at 14:41
  • next question, where do you call loadNibNamed? – borrrden Mar 24 '12 at 14:45
  • It's date, and now I change it'name to dateLabel...and check out the nib file, there is no problem. – jxdwinter Mar 24 '12 at 14:52
  • I dont understand what "where do you call loadNibNamed" mean? I call this function in the cellForRowAtIndexPath.I change the name ,but same excaption, "for the key date" – jxdwinter Mar 24 '12 at 15:16
  • 3
    OK,I made a mistake : dateLabel connected to the file's owner, it should connect to the CellController! Thank you ! – jxdwinter Mar 24 '12 at 15:31
3
  1. Set Custom Class of File's Owner to UITableViewCell.
  2. Set Custom Class of cell to your custom table view cell class myCustomCell.
  3. Outlet your UIlabel in myCustomCell.h.
PatJ
  • 5,996
  • 1
  • 31
  • 37
ypling
  • 31
  • 2
2

Hook up all of your outlets in TododTableViewController XIB (particularly the view outlet), and run again.

CodaFi
  • 43,043
  • 8
  • 107
  • 153