2010-10-04 6 views
0

Je me demandais, existe-t-il des méthodes pour récupérer une cellule spécifique d'un UITableView? Par exemple, d'où je suis je peux accéder à mon UITableView, donc je voudrais appeler quelque chose comme cellForRowAtInteger: 3 et cela retournerait une cellule pour que je puisse la manipuler.Obtention d'un UITableViewCell spécifique d'un UITableView

Des idées?

Merci!

Répondre

2

Vous pouvez utiliser la méthode -cellForRowAtIndexPath: à partir de UITableView. Mais rappelez-vous qu'il retournera nul si la cellule n'est pas visible. Créez votre propre fonction pour créer un NSIndexPath à partir de votre NSInteger.

+0

Cette méthode a besoin d'un NSIndexPath, et je voudrais pouvoir passer un NSInteger ... Mais merci :) (- (UITableViewCell *) cellForRowAtIndexPath: (NSIndexPath *) indexPath) vous – TomShreds

+1

peuvent facilement créer NSIndexPath en utilisant + indexPathWithRow: inSection: méthode. ou vous pouvez écrire fonction de commodité qui accepte entier comme paramètre et crée nsindexpath en interne. mais comme les méthodes UITableView associées fonctionnent avec les chemins d'index, vous devrez les utiliser aussi de toute façon ... – Vladimir

1

-(UITableViewCell *) getCellAt:(NSInteger)index{ 
    NSUInteger indexArr[] = {0,index}; // First one is the section, second the row 

    NSIndexPath *myPath = [NSIndexPath indexPathWithIndexes:indexArr length:2]; 

    return [self tableView:[self tableView] cellForRowAtIndexPath:myPath]; 
} 

Vous pouvez ensuite appeler à l'aide partout:

UITableViewCell *hello = [self getCellAt:4]; // replace 4 with row number 

Si vous avez plus d'une section, alors vous devez changer le 0 en conséquence à la section.

Questions connexes