Comment puis-je obtenir un UITableViewCell
par indexPath
? Comme ça:
J’utilise UIActionSheet
, lorsque je clique sur Confirmer UIButton
je souhaite modifier le texte de la cellule.
Le nowIndex que je définis comme une propriété
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { NSInteger section = [nowIndex section]; NSInteger row = [nowIndex row]; NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; formatter.dateFormat = @"yyyy-MM-dd"; if (section == 0) { if (row == 0) { } else if (row == 1) { UILabel *content = (UILabel *)[[(UITableView *)[actionSheet ] cellForRowAtIndexPath:nowIndex] viewWithTag:contentTag]; content.text = [formatter ssortingngFromDate:checkInDate.date]; } else if (row == 2) { } } } }
[(UITableViewCell *)[(UITableView *)self cellForRowAtIndexPath:nowIndex]
va vous donner une vue imprenable. Mais je ne suis pas sûr de ce que vous demandez exactement! Parce que vous avez ce code et que vous demandez toujours comment obtenir une visionview. Quelques informations supplémentaires vous aideront à répondre 🙂
ADD: Voici une syntaxe alternative qui réalise la même chose sans la dissortingbution.
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:nowIndex];
Enfin, j’obtiens la cellule en utilisant le code suivant:
UITableViewCell *cell = (UITableViewCell *)[(UITableView *)self.view cellForRowAtIndexPath:nowIndex];
Parce que la classe est étendue UITableViewController:
@interface SearchHotelViewController : UITableViewController
Donc, le self
est “SearchHotelViewController”.
Voici un code pour obtenir une cellule personnalisée à partir du chemin d’index
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0]; YourCell *cell = (YourCell *)[tblRegister cellForRowAtIndexPath:indexPath];
Pour Swift
let indexpath = NSIndexPath(forRow: 2, inSection: 0) let currentCell = tblTest.cellForRowAtIndexPath(indexpath) as! CellTest
Vous pouvez utiliser le code suivant pour obtenir la dernière cellule.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:lastIndexPath];
Pour Swift 4
let indexPath = IndexPath(row: 0, section: 0) let cell = tableView.cellForRow(at: indexPath)
Je ne sais pas trop quel est votre problème, mais vous devez spécifier le nom du paramètre comme ça.
-(void) changeCellText:(NSIndexPath *) nowIndex{ UILabel *content = (UILabel *)[[(UITableViewCell *)[(UITableView *)self cellForRowAtIndexPath:nowIndex] contentView] viewWithTag:contentTag]; content.text = [formatter ssortingngFromDate:checkInDate.date]; }
Swift 3
let indexpath = NSIndexPath(row: 0, section: 0) let currentCell = tableView.cellForRow(at: indexpath as IndexPath)!
Rapide
let indexpath = IndexPath(row: 0, section: 0) if let cell = tableView.cellForRow(at: indexPath) as? { cell.backgroundColor = UIColor.red }