Выбрать все ячейки в UITableView
Какой лучший способ выбрать все ячейки в таблице (UITableView), когда пользователь нажимает кнопку на панели инструментов?
Ответы
Ответ 1
Вы можете выбрать метод таблицы сотовых вызовов selectRowAtIndexPath:
[menuTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
Однако вы не можете выбрать несколько ячеек в UITableView.
Если вы хотите показывать и обрабатывать состояние ячеек, вы должны использовать ячейку с дополнительным видом с типом UITableViewCellAccessoryCheckmark. (подробнее см. документы)
Ответ 2
Вот мой метод для перемещения таблицы, он работает хорошо.
for (int i = 0; i < [ptableView numberOfSections]; i++) {
for (int j = 0; j < [ptableView numberOfRowsInSection:i]; j++) {
NSUInteger ints[2] = {i,j};
NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:ints length:2];
UITableViewCell *cell = [ptableView cellForRowAtIndexPath:indexPath];
//Here is your code
}
}
Ответ 3
Это может выбрать все строки в представлении таблицы:
for (NSInteger s = 0; s < self.tableView.numberOfSections; s++) {
for (NSInteger r = 0; r < [self.tableView numberOfRowsInSection:s]; r++) {
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:r inSection:s]
animated:NO
scrollPosition:UITableViewScrollPositionNone];
}
}
Ответ 4
Не пробовал сам, но попробуйте следующее:
В действии вашей кнопки пройдите через indexPath и вызовите его:
for (i = 0; i < [tableView numberOfSections]; i++) {
for (j = 0; j < [tableView numberOfRowsInSection:i]; j++) {
indexPath.row = j;
indexPath.section = i;
[tableView selectRowAtIndexPath:indexPath animated:animated scrollPosition:scrollPosition];
}
}