以下代码正常工作,但它将相同的单元格文本应用于所有部分。我如何根据部分申请选择案例?谢谢。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"English";
break;
case 1:
cell.textLabel.text = @"Chinese";
break;
case 2:
cell.textLabel.text = @"Japanese";
break;
default:
break;
}
return cell;
}
答案 0 :(得分:1)
您可以使用indexPath.section
获取部分编号,就像您使用indexPath.row
作为行号一样。
答案 1 :(得分:0)
您必须检查indexPath.section
以及indexPath.row
:
if (indexPath.section == 0) {
if (indexPath.row) {
...
}
} else if (indexPath.section == 1)
if (indexPath.row) {
...
}
} else if ...