【发布时间】:2010-06-11 03:19:53
【问题描述】:
我创建了一个自定义UITableViewCell,但是当我将单元格出列时,有时它会抛出一个NSInvalidArgumentException:
[UITableViewCell 名称标签]: 无法识别的选择器发送到实例 0x3b4e7f0
由于未捕获而终止应用 例外 'NSInvalidArgumentException',原因: '*** -[UITableViewCell nameLabel]: 无法识别的选择器发送到实例 0x3b4e7f0'
现在,我的自定义 UITableViewCell 确实有一个属性 nameLabel,所以我很困惑为什么它会抛出这个错误。下面是我用来使单元格出列的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
CTMenuItemVO* key = [[[self retrieveCartItems] allKeys] objectAtIndex:row];
NSNumber* quantity = [[self retrieveCartItems] objectForKey:key];
static NSString* SectionsTableIdentifier = @"SectionsTableIdentifier2";
OrderItemCell* cell = (OrderItemCell*)[tableView dequeueReusableCellWithIdentifier:
SectionsTableIdentifier];
if (cell == nil) {
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"OrderItemCell"
owner:nil
options:nil];
for(id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (OrderItemCell*) currentObject;
break;
}
}
}
cell.nameLabel.text = key.Name;
cell.qtyLabel.text = [quantity stringValue];
return cell;
}
更新
将isKindOfClass:[UITableViewCell class] 检查更改为OrderItemCell 会产生另一个错误:
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath 返回一个单元格:
我猜这是因为它离开了for 循环而没有分配类。
【问题讨论】:
标签: iphone objective-c