自定义UITableViewCell错误 [英] error with custom UITableViewCell

查看:70
本文介绍了自定义UITableViewCell错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

 *** 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

Here is the 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

这是我的接线方式:

Here's how I wired it up:

推荐答案

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

正在将文件所有者设置为nil.因此,您无法将任何标签连接到该标签上.相反,请确保单元格的类别为ReservationCell,并且其出口已连接至标签.

Is setting the Files Owner to nil. So you can't wire any of your labels to that. Instead, make sure the class of the cell is ReservationCell and its outlets are connected to the labels.

这篇关于自定义UITableViewCell错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆