¿Cómo poner un UITextField dentro de un UITableViewCell (agrupado)? Quiero que un usuario pueda editarlo.¿Cómo poner un UITextField dentro de una UITableViewCell (agrupada)?
5
A
Respuesta
5
Añadir la UITextField
como una subvista de contentView
del UITableViewCell:
[mycell.contentView addSubview:view];
2
propia aplicación de demostración UICatalog de Apple tiene un ejemplo de colocación de UITextFields en Agrupados UITableView Células: http://developer.apple.com/iphone/library/samplecode/UICatalog/index.html
Compruebe el contenido de TextFieldController.m
Además, hay muchos otros códigos geniales para trabajar con UIKit Objects.
1
Así es como lo he implementado en mi aplicación, sin embargo, obviamente tendrá que cambiar algunas cosas. Espero que esto ayude.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
//adding all the UITextField's to the UITableViewCell is a pain in the ass. Pretty sure this is correct though.
if ([indexPath section] == 0) {
tUser = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
tUser.adjustsFontSizeToFitWidth = YES;
tUser.textColor = [UIColor blackColor];
tPass = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
tPass.adjustsFontSizeToFitWidth = YES;
tPass.textColor = [UIColor blackColor];
if ([indexPath section] == 0) {
if ([indexPath row] == 0) {
tUser.placeholder = @"@JohnAppleseed";
tUser.keyboardType = UIKeyboardTypeEmailAddress;
tUser.returnKeyType = UIReturnKeyNext;
}
if ([indexPath row] == 1) {
tPass.placeholder = @"Required";
tPass.keyboardType = UIKeyboardTypeDefault;
tPass.returnKeyType = UIReturnKeyDone;
tPass.secureTextEntry = YES;
}
}
tUser.backgroundColor = [UIColor whiteColor];
tUser.autocorrectionType = UITextAutocorrectionTypeNo;
tUser.autocapitalizationType = UITextAutocapitalizationTypeNone;
tUser.textAlignment = UITextAlignmentLeft;
tPass.backgroundColor = [UIColor whiteColor];
tPass.autocorrectionType = UITextAutocorrectionTypeNo;
tPass.autocapitalizationType = UITextAutocapitalizationTypeNone;
tPass.textAlignment = UITextAlignmentLeft;
tUser.clearButtonMode = UITextFieldViewModeNever;
tPass.clearButtonMode = UITextFieldViewModeNever;
[tUser setEnabled:YES];
[tPass setEnabled:YES];
//[tUser release];
//[tPass release];
}
if ([indexPath section] == 0) { // Email & Password Section
if ([indexPath row] == 0) { // Email
cell.textLabel.text = @"Username";
[cell addSubview:tUser];
[tUser setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_name_preference"]];
}
else {
cell.textLabel.text = @"Password";
[cell addSubview:tPass];
[tPass setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_pass_preference"]];
}
}
return cell; }
Espero que ayude.
Cuestiones relacionadas
- 1. Cómo anidar un UITextField dentro de una UITableViewCell?
- 2. La edición de un UITextField dentro de una UITableViewCell falla
- 3. UITextField en un UITableViewCell
- 4. UITextField en UITableViewCell Help
- 5. Acceso a UITextField en una UITableViewCell personalizada
- 6. Crear UITableViewCell personalizado dentro de un Storyboard
- 7. ¿Cómo seleccionar un UITextField?
- 8. Poner un título de solo lectura en un UITextField
- 9. Horizontal UIScrollView dentro de una UITableViewCell
- 10. ¿Subvista UITextField de UITableViewCell para convertirse en el primer respondedor?
- 11. ¿Cómo funciona ItemContainerGenerator.ContainerFromItem con una lista agrupada?
- 12. ¿Un UITextField con estado de primera respuesta en una UITableViewCell previene la reutilización de la celda?
- 13. ¿Cómo poner Editable edittext dentro de una vista de lista?
- 14. ¿Cómo poner php dentro de JavaScript?
- 15. Poner marca de verificación en el lado izquierdo de UITableViewCell
- 16. ¿Cómo se insertan tokens de texto azul dentro de UITextField?
- 17. Recuperar un marco UITableViewCell
- 18. ¿Es posible poner una lista dentro de una etiqueta span?
- 19. Recargue un UITable sobre la marcha al editar un UITextField dentro de una de las celdas
- 20. ¿Puedo poner una sentencia return dentro de una cerradura
- 21. Cómo crear un UITextfield multilínea?
- 22. Cómo crear una UITableViewCell con un fondo transparente
- 23. Hibernate ¿Buscar en una configuración agrupada?
- 24. ¿Cómo creo un UITextField transparente?
- 25. Cómo concatenar/unir cadenas de una columna agrupada en SQLite?
- 26. UITextField focus
- 27. ¿Cómo crear un cuadro de selección agrupada usando simple_form?
- 28. Cómo poner a cero un número dentro de una celda de Excel
- 29. iPhone UITableViewCell layer shadow
- 30. poner html dentro de un iframe (usando javascript)