请浏览链接 Using multiple custom UITableViewCells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
return nil;
}
这里 我不明白你为什么补充 在大括号结束前返回零。
答案 0 :(得分:1)
你永远不应该从-tableView:cellForRowAtIndexPath:
返回nil。我相信程序员用它来表示一个无法访问的代码路径,并防止编译器抱怨控件已经到达函数的末尾而没有返回任何内容。
答案 1 :(得分:0)
该代码中有一个错误的缩进。
这是正确的缩进:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
/*
UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
[backView release];
*/
static NSString *cellIdentifier1 = @"DetailCellStyle1";
static NSString *cellIdentifier2 = @"DetailCellStyle2";
if (indexPath.section == 0) {
// Load from nib
DetailCellViewController *cell = (DetailCellViewController *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier1];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle]
loadNibNamed:@"DetailCellView"
owner:nil
options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (DetailCellViewController *) currentObject;
break;
}
}
}
return cell;
}
else {
// Load from nib
DetailCellViewController2 *cell = (DetailCellViewController2 *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle]
loadNibNamed:@"DetailCellView"
owner:nil
options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (DetailCellViewController2 *) currentObject;
break;
}
}
}
return cell;
}
return nil;
}
还有return cell
;