我得到了这个错误:
*** 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下面是我如何把它连接起来的:

发布于 2011-03-18 02:02:19
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ReservationCell"
owner:nil
options:nil];正在将文件所有者设置为nil。所以你不能把你的任何标签都连接到上面。相反,请确保单元格的类是ReservationCell,并且其插座连接到标签。
发布于 2012-05-14 19:07:44
对于像我这样已经接触到这个主题但不能找到解决方案的人,这里是这个问题的快速解决方案:
在界面构建器中,当您应该从单元格视图中链接IBOutlets时,您却链接了来自文件所有者的文件。这就是你得到这些错误的原因。
祝你好运!
发布于 2012-03-21 21:39:57
当在File的接口构建器中,将CustomCell的Owner自定义类设置为您的CustomCell类时,就会发生此问题。
应始终将视图文件的所有者自定义类设置为您的CustomCell类。
此外,您还需要使用您的表视图单元格的Nib名称初始化它。
示例(NotificationCell是我的自定义单元格类):http://i42.tinypic.com/29pw0a8.png
https://stackoverflow.com/questions/5343172
复制相似问题