UITableView, Устанавливающий некоторые ячейки как “неможно выбрать”

вы должны использовать правильную версию 28.0.0, просто нажмите alt-enter, чтобы получить предложения, и вы получите: реализацию 'com.android.support:cardview-v7:28.0.0'

внедрение' com.android.support:recyclerview-v7:28.0.0'

и ваша ошибка будет исправлена.

108
задан Mugunth 1 May 2009 в 17:45
поделиться

5 ответов

Установите для свойства ячейки таблицы selectionStyle значение UITableViewCellSelectionStyleNone . Это должно предотвратить выделение, и вы также можете проверить это свойство в вашем tableView: didSelectRowAtIndexPath: .

151
ответ дан 24 November 2019 в 03:25
поделиться

Apple says that the first thing you should do in didSelectRowAtIndexPath is to deselect the row

[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];

Then you can change the AccessoryType to be a checkmark, or none, etc. So when you enter didSelectRowAtIndexPath you could deselect the row, and if its not meant to be selected, simply don't check that row.

Table View Programming Guide

3
ответ дан 24 November 2019 в 03:25
поделиться

To Prevent Row Selection

To completely prevent selection of the UITableViewCell, have your UITableViewDelegate implement tableView:willSelectRowAtIndexPath:. From that method you can return nil if you do not want the row to be selected.

- (NSIndexPath *)tableView:(UITableView *)tv willSelectRowAtIndexPath:(NSIndexPath *)path
{
    // Determine if row is selectable based on the NSIndexPath.

    if (rowIsSelectable) {
        return path;
    }
    return nil;
}

This prevents the row from being selected and tableView:didSelectRowAtIndexPath: from being called. Note, however, that this does not prevent the row from being highlighted.

To Prevent Row Highlighting

If you would like to prevent the row from being visually highlighted on touch, you can ensure that the cell's selectionStyle is set to UITableViewCellSelectionStyleNone, or preferably you can have your UITableViewDelegate implement tableView:shouldHighlightRowAtIndexPath: as follows:

- (BOOL)tableView:(UITableView *)tv shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Determine if row is selectable based on the NSIndexPath.

    return rowIsSelectable;
}
194
ответ дан 24 November 2019 в 03:25
поделиться

Эта проблема тоже перепробовала все, что уже упоминалось. Последний трюк, который помог избавиться от "синей вспышки" при выборе ячейки таблицы, заключался в добавлении этой строки:

self.myTableView.allowsSelection = NO;

Не уверен, была ли это одна строка или все вместе, но в качестве общего итога я больше не получаю ни выбора синего цвета, ни даже синей вспышки. Счастливо!

9
ответ дан 24 November 2019 в 03:25
поделиться

используйте это:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
16
ответ дан 24 November 2019 в 03:25
поделиться
Другие вопросы по тегам:

Похожие вопросы: