Je suis encore en train de me familiariser avec l'iPhone SDK.La sélection UITableViewCell reste dans toutes les cellules!
C'est ce que je suis en train de faire:
j'ai un UIScrollView et chaque vue de défilement a un UITableView et moi avons mis en œuvre une coutume UITableViewCell.
La fonctionnalité souhaitée est initialement il n'y a aucune sélection, puis l'utilisateur sélectionne la ligne et fait défiler et fait une autre sélection dans la vue de défilement suivante et continue. Je veux que la sélection reste, afin que l'utilisateur puisse changer la sélection plus tard.
Cependant, ce qui se passe dans mon cas est le premier et le second UITableViews sont bien, la ligne sélectionnée reste sélectionnée, mais dans la troisième UITableView je vois une ligne "déjà" sélectionnée qui est la même que la première UITableView. Je ne veux pas voir un sélectionné. Je sais que je fais quelque chose de stupide mais je n'arrive pas à comprendre quoi. Toute aide sera grandement appréciée.
Merci, Amy
Voici les sources de données pertinentes et les méthodes délégués.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
static NSString * ChoiceTableCellIdentifier = @"ChoiceTableCellIdentifier";
choiceTableCell = (ChoiceTableCell *)[tableView dequeueReusableCellWithIdentifier:ChoiceTableCellIdentifier];
if(choiceTableCell == nil)
{
choiceTableCell = [[[ChoiceTableCell alloc]
initWithFrame:CGRectZero
reuseIdentifier:ChoiceTableCellIdentifier] autorelease];
}
return choiceTableCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%s", __FUNCTION__);
int newRow = [indexPath row];
int oldRow = [lastIndexPath row];
if ((newRow != oldRow) || (newRow == 0))
{
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
UIImageView *indicatorN = (UIImageView *)[newCell.contentView viewWithTag:SELECTION_INDICATOR_TAG_1];
indicatorN.image = [UIImage imageNamed:@"selected.png"];
newCell.backgroundView.backgroundColor = [UIColor clearColor];
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastIndexPath];
UIImageView *indicatorO = (UIImageView *)[oldCell.contentView viewWithTag:SELECTION_INDICATOR_TAG_1];
indicatorO.image = [UIImage imageNamed:@"notSelected.png"];
oldCell.backgroundView.backgroundColor = [UIColor clearColor];
lastIndexPath = indexPath;
}
}