當我在'didSelectRowAtIndexPath'中選擇播放器並在所選行上添加複選標記時,它會添加一個額外複選標記。UITableView didSelectRowAtIndexPath在水龍頭處添加額外複選標記
如果我點擊row = 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--;
}
}
}
THX夥計你的問題,你的代碼片段保存我問另一個重複的問題! – codejunkie 2012-03-20 20:21:34
我們歡迎您的傢伙 – PeterK 2012-03-20 21:55:21