У меня есть UITableView
, и когда я выбираю ячейку, я хочу поставить галочку справа от ячейки .... это довольно просто.
Для этого я сделал следующее:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableViewMieux deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
if (selectedCell.accessoryType == UITableViewCellAccessoryNone)
{
UIImageView *checkBox = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkbox-pressed.png"]] autorelease];
checkBox.frame = CGRectMake(0, 0, 20, 20);
selectedCell.accessoryView = checkBox;
selectedCell.accessoryType=UITableViewCellAccessoryCheckmark;
}
else if (selectedCell.accessoryType==UITableViewCellAccessoryCheckmark)
{
UIImageView *checkBox = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkbox.png"]] autorelease];
checkBox.frame = CGRectMake(0, 0, 20, 20);
selectedCell.accessoryView = checkBox;
selectedCell.accessoryType=UITableViewCellAccessoryNone;
}
[tableViewMieux reloadData];
}
Все отлично работает, за исключением того факта, что когда я выбираю первую ячейку, она помечается галочкой, а пятая ячейка тоже автоматически помечается.И так далее ... если я выберу вторую ячейку, это будет помечено галочкой ... и будет помечена другая ячейка в нижней части tableView.
Итак, каждый раз, когда я выбираю и отмечаю ячейку и дополнительную ячейкустановится отмеченным.
Question:Why?What is the right way to do it?
РЕДАКТИРОВАТЬ:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableViewMieux dequeueReusableCellWithIdentifier:@"CellRecherchePartenaires"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"CellRecherchePartenaires"] autorelease];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.backgroundView.opaque = NO;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.opaque = NO;
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.highlightedTextColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.opaque = NO;
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.highlightedTextColor = [UIColor whiteColor];
cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
cell.accessoryView=UITableViewCellAccessoryNone;
}
// Set up the cell...
[[cell textLabel] setText: [tableArray objectAtIndex:indexPath.row]] ;
return cell;
}