Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom 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;
 }

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!

like image 356
jxdwinter Avatar asked Mar 24 '12 14:03

jxdwinter


3 Answers

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?

like image 145
borrrden Avatar answered Oct 10 '22 02:10

borrrden


  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.
like image 3
ypling Avatar answered Oct 10 '22 01:10

ypling


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

like image 2
CodaFi Avatar answered Oct 10 '22 01:10

CodaFi