Multi Select Table View Cell и без стиля выделения - PullRequest
3 голосов
/ 03 февраля 2011

У меня есть базовый UITableView, в котором я хочу включить галочки в стиле Mail.app , не имея стиля выделения.У меня есть следующий фрагмент:

#define UITableViewCellEditingStyleMultiSelect (3)

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleMultiSelect;
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

Однако, это никогда не будет отображать галочки при выделении (хотя отображаются пустые кружки).Есть идеи как это исправить?Я знаю, что он использует недокументированные функции, но я бы очень хотел добавить поддержку для галочек.В моем примере используется очень настроенный UITableViewCell, и я не могу включить стиль выделения!

sample table view

1 Ответ

6 голосов
/ 03 февраля 2011
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

    if (self.tableView.isEditing) {
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    } else {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    return cell;
}

-(UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleMultiSelect;
}

-(IBAction) switchEditing {
    [self.tableView setEditing:![self.tableView isEditing]];
    [self.tableView reloadData]; // force reload to reset selection style
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...