Reputation: 745
following code works properly but it applies same cell text to all sections. How could I apply selection case also depending on section? Thank you.
- (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;
}
Upvotes: 0
Views: 102
Reputation: 5540
You have to check for the indexPath.section
and also indexPath.row
:
if (indexPath.section == 0) {
if (indexPath.row) {
...
}
} else if (indexPath.section == 1)
if (indexPath.row) {
...
}
} else if ...
Upvotes: 0
Reputation: 118691
You can use indexPath.section
to get the section number, just like how you're using indexPath.row
for the row number.
Upvotes: 1