2009-12-07 10 views
0
  • (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {identifiant sélection de bouton de chaque ligne dans TableView?

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    btn.frame = CGRectMake(230.0f, 4.0f, 60.0f, 36.0f); 
    [btn setTitle:@"OK" forState:UIControlStateNormal]; 
    [btn setTitle:@"OK" forState:UIControlStateSelected]; 
    [btn addTarget:self action:@selector(onClickRename:) forControlEvents:UIControlEventTouchUpInside]; 
    [cell addSubview:btn]; 
    
    return cell; 
    

    }

mais si l'utilisateur sélectionne le bouton de ligne particulière, Je peux changer cette image par onClickRename ... mais puis-je obtenir dans quelle image de la ligne a été touchée

  • (vide) tableView: (UITableView ) tableView didSelectRowAtIndexPath: (NSIndexPath) indexPath?

Répondre

2

que vous pourriez faire dans votre configuration cellulaire quelque chose comme

[btn setTag:[indexPath] row] 

, puis

- (void) onClickRename:(id)sender { 
    int row = sender.tag; 
} 

vous sauriez quelle ligne la table a été frappé.

0

Apple utilise la technique suivante dans leur code Accessory exemple:

- (void)checkButtonTapped:(id)sender event:(id)event 
{ 
    NSSet *touches = [event allTouches]; 
    UITouch *touch = [touches anyObject]; 
    CGPoint currentTouchPosition = [touch locationInView:self.tableView]; 
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition]; 
    if (indexPath != nil) 
    { 
     // do what you want with the item at indexPath 
    } 
} 
Questions connexes