Применить различные свойства ячейки в зависимости от раздела - PullRequest
0 голосов
/ 23 августа 2011

следующий код работает правильно, но он применяет один и тот же текст ячейки ко всем разделам. Как я могу применить выбор выбора также в зависимости от раздела? Спасибо.

- (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;
}

Ответы [ 2 ]

1 голос
/ 23 августа 2011

Вы можете использовать indexPath.section, чтобы получить номер раздела, так же, как вы используете indexPath.row для номера строки.

0 голосов
/ 23 августа 2011

Вы должны проверить на indexPath.section, а также indexPath.row:

if (indexPath.section == 0) {

    if (indexPath.row) {

        ...
    }

} else if (indexPath.section == 1)

    if (indexPath.row) {

        ...
    }

} else if ...
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...