Je me suis cogné la tête contre le mur sur celui-ci depuis un certain temps maintenant. Toute contribution ou direction est grandement appréciée.UITextField dans la cellule UITableView renvoie null
L'objectif est donc de créer un formulaire de connexion à partir des champs de texte d'une table. Ces informations d'utilisateur, une fois collectées, seront transmises à un tableau dans un contrôleur de vue séparé afin de pouvoir être stockées dans une liste de "favoris".
J'ai donc créé le formulaire qui a l'air bien et tout sauf quand je console les résultats de formulaire les champs sont retournés (null). J'ai choisi le site pour les réponses, mais rien ne peut être exact. Ci-dessous, la méthode cellForRowAtIndexPath: Je pense que le problème est peut-être lié à la création de textFields. Encore une fois, toute contribution est appréciée!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:[indexPath section]]];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:CellIdentifier] autorelease];
textField = [[UITextField alloc] initWithFrame:CGRectMake(120, 13, 375, 30)];
[textField retain];
}
textField.adjustsFontSizeToFitWidth = NO;
textField.font = [UIFont fontWithName:@"Helvetica" size:14.0];
textField.textColor = [UIColor darkGrayColor];
textField.returnKeyType = UIReturnKeyDone;
textField.backgroundColor = [UIColor clearColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
textField.textAlignment = UITextAlignmentLeft;
textField.clearButtonMode = UITextFieldViewModeNever;
textField.delegate = self;
if ([indexPath section] == 0) {
switch (indexPath.row) {
case 0:
textField.placeholder = @"Optional";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 0;
break;
case 1:
textField.placeholder = @"";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 1;
break;
case 2:
textField.placeholder = @"";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 2;
break;
case 3:
textField.placeholder = @"";
textField.secureTextEntry = YES;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 3;
break;
case 4:
textField.placeholder = @"Optional";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeDefault;
textField.tag = 4;
break;
case 5:
textField.placeholder = @"Optional";
textField.secureTextEntry = NO;
textField.keyboardType = UIKeyboardTypeNumberPad;
textField.tag = 5;
break;
}
}
[textField setEnabled: YES];
[cell addSubview:textField];
cell.textLabel.text = [listData objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
cell.editing = YES;
return cell;
}
Point pris. Alors que j'ai complètement l'intention de revenir en arrière et de créer une cellule personnalisée, est-ce que cela répond à ma question initiale? –
Ce sera, quand vous allez-y et le faire. – jer