ЭтоПроблема реализации UITableView, что позволяет множественный выбор строк
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
... изменяет «accessoryType» каждой 6-й ячейки, а не просто в выбранной строке. Что мне не хватает?
Благодаря
ОБНОВЛЕНО: Вот код создания ячейки ...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *TC = @"TC";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: TC];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PlayerTableViewCell] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [NSString stringWithFormat:@"Person %d", row+1];
return cell;
}
МОЕ РЕШЕНИЕ на основе отмеченная ответ ниже ...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// EVERY row gets its one Identifier
NSString *TC = [NSString stringWithFormat: @"TC%d", indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: TC];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TC] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [NSString stringWithFormat:@"Person %d", row+1];
return cell;
}
Если лучше, я все уши. Было бы неплохо, если бы мы могли просто изменить SPECICIC Cell в соответствии с NSIndexPath, переданным когда-нибудь (по крайней мере, это кажется мне намного более интуитивным).
Разве это не против лучшей практики? И может ли это начало иметь некоторые отрицательные последствия, связанные с ростом числа строк? – wgpubs
Хорошо, еще один способ: проверить, существует ли (rowNumber + 1) в массиве выигрышаNumbers и заменить аксессуар в методе cellForRowAtIndexPath. Это тоже должно работать. – kovpas