J'ai un UITableViewCell (avec sous-classe UITableViewCell associée, .m & .h) créé dans IB qui contient un UITextField. UITextField est connecté à un IBOutlet dans la sous-classe UITableViewCell et possède également une propriété. Dans mon contrôleur de vue de la table J'utilise cette cellule personnalisée avec le code suivant:Accès à UITextField dans un UITableViewCell personnalisé
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"textfieldTableCell"];
if (cell == nil) {
// Create a temporary UIViewController to instantiate the custom cell.
UIViewController *temporaryController = [[UIViewController alloc] initWithNibName:@"TextfieldTableCell" bundle:nil];
// Grab a pointer to the custom cell.
cell = (TextfieldTableCell *)temporaryController.view;
// Release the temporary UIViewController.
[temporaryController release];
}
return cell;
}
Le UITextField affiche bien et le clavier apparaît quand on clique dessus comme prévu, mais comment puis-je accéder (obtenir la propriété .text) le UITextField que chaque rangée contient? et comment gérer la méthode 'textFieldShouldReturn' des UITextFields?
Bravo Rog, je vais essayer ça quand je reviendrai à mon mac. Je me demande comment Apple le fait, comme l'application Paramètres, j'aurais pensé que je serais un peu plus simple/propre que cela. Je suppose qu'ils le font probablement d'une manière complètement différente et tous avec du code aussi. – Darthtong