Я сохраняю NSMutableArray с именем checkedIndexPaths, чтобы я знал, какие indexPaths проверяются. Сохранение такого массива позволяет легко ограничить количество ячеек, которые может проверить пользователь. Вот пример моего didSelectRowAtIndexPath:
я выбираю игрока в didSelectRowAtIndexPath и добавляю галочку в выбранную строку, добавляется дополнительная галочка.
Если я коснусь строки = 0, это добавляет галочку к строке = 0 и строке = 11. Это означает, что две строки отмечены одним касанием. Если я коснусь row = 1, он добавляет дополнительную галочку к row = 10, поэтому добавляет 10 галочек вперед. Кажется, что он только добавляет галочку, так как игрок не попадает в фактический список игроков.
Любая помощь будет очень высоко ценится.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"indexPath: %i", indexPath.row);
// To many players selected
if (nrOfSelectedPlayers == 6) { //This is max players allowed
UIAlertView *alertPlayer = [[UIAlertView alloc] initWithTitle:@"VARNING"
message:@"Du kan maximalt spela \n med sex spelare!"
delegate:self
cancelButtonTitle:@"Tillbaka"
otherButtonTitles:nil];
[alertPlayer show];
[alertPlayer release];
nrOfSelectedPlayers--;
checkDeletePlayer = YES;
}
else {
// Handle the number of selected players to be able to delete player +6
if (checkDeletePlayer == YES) {
checkDeletePlayer = NO;
nrOfSelectedPlayers++;
}
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[selectedPlayersArray addObject:cell.textLabel.text];
nrOfSelectedPlayers++;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
selectedPlayer = cell.textLabel.text;
for (int oo = 0; oo < nrOfSelectedPlayers; oo++) {
if ([selectedPlayersArray objectAtIndex:oo] == cell.textLabel.text) {
[selectedPlayersArray removeObjectAtIndex:oo];
nrOfSelectedPlayers--;
}
}
//nrOfSelectedPlayers--;
}
}
}