2010-11-18 3 views
0

Je veux juste sélectionner ma première cellule de ma première section, son quelque chose de simple, mais il ne veux pas travailler ...Impossible de sélectionner la cellule, mais je peux régler la Textlabel

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"CellIdentifier"; 

    // Dequeue or create a cell of the appropriate type. 
    UITableViewCell *cell; 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    cell.textLabel.font = [UIFont boldSystemFontOfSize:17]; 
    cell.selectionStyle = UITableViewCellSelectionStyleBlue; 


    switch (indexPath.section) { 
     case 0: 
     { 
      NSString *cellIconName = [[self subViewIconNames] objectAtIndex:[indexPath row]]; 
      UIImage *cellIcon = [UIImage imageNamed:cellIconName]; 
      [[cell imageView] setImage:cellIcon]; 
      cell.imageView.alpha = 0.5; 
      cell.textLabel.textColor = [UIColor grayColor]; 
      cell.textLabel.text = [self.subViewNames objectAtIndex:indexPath.row]; 


      if ([MyAppDelegate sharedAppDelegate].inSubView) { 
        cell.userInteractionEnabled = NO; 
       if (indexPath.row == 0) { 
        firstIndexPath =indexPath; 
        cell.selected = YES; 
        cell.textLabel.text = @"yes this changes"; 
       } 
      } 



      break; 
     } 
... 

Ainsi, les changements de Textlabel à « Oui cela change », mais pas sélectionné ...

J'ai essayé différentes approches, aussi cela après le reload:

NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0]; 
     [[MyAppDelegate sharedAppDelegate].rootViewController.tableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionBottom]; 

Je ne sais pas où regarder ... s'il vous plaît aider

Répondre

0

Je ne suis pas sûr de comprendre ce que vous essayez de faire, mais peut-être que vous devriez essayer d'utiliser mis en évidence en plus choisi:

cell.selected = YES; 
cell.highlighted = YES; 
+0

Non il n'est toujours pas sélectionné ... très bizarre – meersmans

+0

avez-vous essayé d'utiliser ce setter [cellule définieSélectionnée: OUI animée: OUI]; ? – Romain

0

Essayez quelque chose comme ceci:

- (void) tableView:(UITableView *)tableView selectAndScrollToIndexPath:(NSIndexPath *)newSelectionIndexPath { 

    [tableView selectRowAtIndexPath:newSelectionIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 
    [[tableView cellForRowAtIndexPath:newSelectionIndexPath] setSelected:YES animated:NO]; 

    [tableView scrollToRowAtIndexPath:newSelectionIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO]; 
} 
Questions connexes