错误: - 使用未声明的标识符单元格。无法在一个视图控制器中加载两个表视图
无法在一个视图控制器中加载两个自定义单元格。
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
if (tableView == tableView_grantRecordAccess)
{
UITableViewCell *cell = [tableView_grantRecordAccess dequeueReusableCellWithIdentifier:@"EHSRecordAccessGrantCell"];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"EHSRecordAccessGrantCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
return cell;
}
else if (tableView == tableView_accessRecordRequest) {
UITableViewCell *cell = [tableView_accessRecordRequest dequeueReusableCellWithIdentifier:@"EHSAccessRecordCell"];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"EHSAccessRecordCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
}
return cell;
}
检查XIB中的单元格标识符。 –
其他条件,如果我们得到错误使用未声明的标识符单元格 –
当您返回单元格时,在else else条件中,右括号错位(“}”),因此未定义。正确缩进您的代码,您会看到。它应该在'return cell;'之后而不是之前。 – Larme