我收到此错误:

 *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x5a37750> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key destination.'

以下是代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ReservationCell";

    ReservationCell *cell = (ReservationCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ReservationCell" owner:nil options:nil];
        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell = (ReservationCell *) currentObject;
                break;
            }
        }
    }


    //cell.origin.text = [[data objectAtIndex:indexPath.row] origin];
    //cell.destination.text = [[data objectAtIndex:indexPath.row] destination];
    //cell.time_range.text = [[data objectAtIndex:indexPath.row] time_range];

    return cell;
}

这是 ReservationCell.h
@interface ReservationCell : UITableViewCell {
    UILabel * origin;
    UILabel * destination;
    UILabel * time_range;
}

@property (nonatomic, retain) IBOutlet UILabel * origin;
@property (nonatomic, retain) IBOutlet UILabel * destination;
@property (nonatomic, retain) IBOutlet UILabel * time_range;

@end

这是我的接线方式:

最佳答案

NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ReservationCell"
                                                         owner:nil
                                                       options:nil];

将“文件所有者”设置为nil。所以你不能将任何标签连接到它。相反,请确保单元格的类是 ReservationCell 并且其导出连接到标签。

10-07 14:33