coloqué una UITextField en un UIAlertView y se trasladó hacia arriba de modo que el teclado no sería cubrirlo con el siguiente código:UITextField en UIAlertView en iPhone: ¿cómo hacer que responda?
[dialog setDelegate:self];
[dialog setTitle:@"Enter Name"];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"OK"];
UITextField * nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
[dialog addSubview:nameField];
CGAffineTransform moveUp = CGAffineTransformMakeTranslation(0.0, 100.0);
[dialog setTransform: moveUp];
[dialog show];
también tengo el siguiente código para hacer frente a la vista de alertas:
- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%d", (int) buttonIndex);
if (buttonIndex == 1) { // OK pushed
NSLog([alert textField].text); // does not log anything
} else {
// Cancel pushed
}}
que también tienen un archivo que contiene UIAlertViewExtended.h:
@class UITextField, UILabel;
@interface UIAlertView(Extended)
-(UITextField *)textField;
@end
Mi pregunta es ¿cómo puedo obtener el texto introducido el usuario y cómo puedo dismis s el teclado?
Gracias, Ben
iPhone OS 4.0 parece hacer las cosas de transformación automáticamente, probablemente tendremos que introducir una comprobación si su SDK base es 4.0 y el SDK mínimo que admitirá es 3.0, por lo que el código CGAffineTransform se ejecuta solo si el sistema operativo nativo es 3.0 o 3.1, para iPhone OS 4.0 ¡omita esta parte del código! –