2010-07-14 6 views
2

Je crée un programme de liste de contrôle en utilisant UITableView et j'ai réussi à tout implémenter jusqu'à la sélection et à faire apparaître une coche. Cependant, quand je défile loin des cellules. La coche disparaît.UITableView Checklist

je le code suivant:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"CellIdentifier"; 

// Dequeue or create a cell of the appropriate type. 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

} 

// Configure the cell. 
if(tableView == Table1){ 

    switch(indexPath.section){ 
     case 0: 
      cell.textLabel.text =[array1 objectAtIndex:indexPath.row]; 
      break; 
     case 1: 
      cell.textLabel.text = [array2 objectAtIndex:indexPath.row]; 
      break; 
     case 2: 
      cell.textLabel.text = [array3 objectAtIndex:indexPath.row]; 
      break; 
    } 

    //cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row]; 
} 

//if([indexPath compare:[selectedArray objectAtIndex:i]] == NSOrderedSame){ 
if([selectedArray containsObject:cell]){ 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
}else{ 
     cell.accessoryType = UITableViewCellAccessoryNone; 
} 
//} 
if(tableView == sauceTable){ 
    cell.textLabel.text = [array4 objectAtIndex:indexPath.row]; 
} 

return cell;} 

Et:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
UITableViewCell *c= [aTableView cellForRowAtIndexPath: indexPath]; 
c.accessoryType = UITableViewCellAccessoryCheckmark; 
[selectedArray addObject: c]; 
} 

Toutes les idées?

Répondre

1

Résolu. Utiliser NSIndexPath au lieu de UITableViewCell pour le tableau de sélection

+0

Pouvez-vous montrer un code que vous avez utilisé pour résoudre ce problème? –