2009-09-28 8 views
2

Lorsque j'appuie sur la première cellule de ma vue de table didSelectRowAtIndexPath n'est pas déclenchée ... Est-ce que quelqu'un a l'air de le savoir et/ou sait pourquoi cela se produit? Toutes les autres cellules de ma table fonctionnent très bien et je mets un point d'arrêt dans mon code en didSelectRowAtIndexPath l'application ne va pas dans ce code si la première cellule est tapée mais ira dans le code si l'autre cellule est engagée. Voici un code:Lorsque j'appuie sur la première cellule de ma table, la commande didSelectRowAtIndexPath n'est pas déclenchée

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSInteger row = 0; 
    return row; 
} 

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSInteger row = [indexPath row]; 
    if (row == 0) 
     return nil; 

    return indexPath; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //NSUInteger row = [indexPath row]; 
    //NSString *rowValue = [poolListData objectAtIndex:row]; 

    int newRow = [indexPath row]; 
    int oldRow = [lastIndexPathForPoolList row]; 

    if (newRow != oldRow) 
    { 
     UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath]; 
     newCell.accessoryType = UITableViewCellAccessoryCheckmark; 

     UITableViewCell *oldCell = [tableView cellForRowAtIndexPath: lastIndexPathForPoolList]; 
     oldCell.accessoryType = UITableViewCellAccessoryNone; 

     lastIndexPathForPoolList = indexPath; 
    } 

    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

- (NSInteger)tableViewForDelete:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [poolListData count]; 
} 

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

    static NSString *DeleteMeCellIdentifier = @"DeleteMeCellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DeleteMeCellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:DeleteMeCellIdentifier] autorelease]; 
    } 

    NSInteger row = [indexPath row]; 
    cell.text = [self.poolListData objectAtIndex:row]; 
    return cell; 
} 

#pragma mark - 
#pragma mark Table View Delegate Methods 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 50; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSUInteger row = [indexPath row]; 
    [self.poolListData removeObjectAtIndex:row]; 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 

Merci pour votre temps et toute aide que vous pouvez me donner!

+0

Désolé pour le bordel ... Je n'arrive pas à obtenir le code pour le coller correctement. – Jeff

+0

corrigé cela pour vous. Où est lastindexpathforpoollist initializerd? – ennuikiller

+0

avez-vous configuré le tableview.delegate? – CiNN

Répondre

3

Je pense que votre retour est nul dans willSelectRowForIndexPath pour la première ligne. Cela empêchera la sélection de la ligne.

+0

Comment y arriver !!! Je l'ai pris et maintenant je peux sélectionner la première rangée, mais seulement après avoir choisi une autre rangée d'abord !! Je vous remercie!! – Jeff

Questions connexes