Tengo un uitextfield donde se escribe una fecha ... ¿cómo puedo mostrar en la parte inferior de la página un uidatepicker en lugar de un teclado estándar? gracias de antemanoios UITextField para editar con uidatepicker
6
A
Respuesta
4
Asegúrese de que su clase implementa el protocolo UITextFieldDelegate
. A continuación, reemplazar el método shouldBeginEditing
delegado para volver FALSO:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//check if it is the UITextField you don't want the keyboard for
if (textField != dateTextField)
return TRUE;
//present your UIDatePicker
//see instructions below
//Return false to prevent the keyboard from appearing.
return FALSE;
}
recomiendo el uso de otra UIViewController
que contiene una UIDatePicker
y utilizar presentModalViewController
mostrarlo. Esto se ajusta a las Pautas de interfaz de usuario.
5
UITextField proporciona un mecanismo para esto. Se supone que debes poder configurar otra vista (como un selector de fecha) como inputView. Ver este post:
3
Usted puede utilizar el siguiente código;
//first of all, you have to declare the datePicker and then use the following code;
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[dateLabel resignFirstResponder]; //the textField that you will set the selected date
datePicker = [[UIDatePicker alloc] init]; //declared uidatepicker component
pickerViewDate = [[UIActionSheet alloc] initWithTitle:@"Select the date!"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
datePicker.datePickerMode = UIDatePickerModeDate; //set your spesific mode
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; //or another LocaleIdentifier instead of en_US
[dateFormatter setDateFormat:@"dd.MM.yyyy"]; //desired format
[datePicker addTarget:self action:@selector(dateChanged) forControlEvents:UIControlEventValueChanged]; //the function would be fired when user change the date in datePicker
//now preparing the toolbar which will be displayed at the top of the datePicker
pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle=UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonClicked)]; //barbutton item is "DONE" and doneButtonClicked action will be fired when user clicks the button.
[barItems addObject:flexSpace]; // set the left of the bar
[pickerToolbar setItems:barItems animated:YES];
[pickerViewDate addSubview:pickerToolbar];
[pickerViewDate addSubview:datePicker];
[pickerViewDate showInView:self.view];
[pickerViewDate setBounds:CGRectMake(0,0,320, 464)]; //you can change the position
}
y acciones adicionales;
-(IBAction)dateChanged{
NSDateFormatter *FormatDate = [[NSDateFormatter alloc] init];
[FormatDate setLocale: [[NSLocale alloc]
initWithLocaleIdentifier:@"en_US"]];
[FormatDate setDateFormat:@"dd.MM.yyyy"];
dateLabel.text = [FormatDate stringFromDate:[datePicker date]];
}
-(BOOL)closeDatePicker:(id)sender{
[pickerViewDate dismissWithClickedButtonIndex:0 animated:YES];
[dateLabel resignFirstResponder];
return YES;
}
-(IBAction)doneButtonClicked{
[self closeDatePicker:self];
}
Cuestiones relacionadas
- 1. Reemplazo de entrada de UITextField con un UIDatePicker
- 2. IOS: UItextfield deshabilitado
- 3. UITextField shadow no se muestra al editar
- 4. IOS: UIDatePicker se muestra mal con un fondo negro
- 5. iOS - Descartar UIDatePicker presentado como inputView
- 6. iOS 5 - Configurar la fecha mínima de UIDatePicker para "hoy"
- 7. 'error de contexto no válido 0x0', al editar uitextfield usando teclado de varios bytes con iOS 6.0
- 8. UIDatePicker septiembre de 1978 error en ios 4.x
- 9. iOS: ¿Cómo enviar la clave a UITextField?
- 10. iOS SDK: ¿cómo obtener la fecha de un UIDatePicker?
- 11. resignFirstResponder entendimiento con UITextField
- 12. ¿Cómo reescribo el componente UIDatePicker?
- 13. Permitir solo caracteres alfanuméricos para un UITextField
- 14. UIDatePicker - Localización de problemas
- 15. UIDatePicker para mostrar solo el año
- 16. iphone uidatepicker localization
- 17. UIDatePicker Método DidSelectRow?
- 18. Interface Builder UIDatePicker
- 19. UIDatePicker volver equivocada NSDate
- 20. Usando kdiff3 para editar diffs con git
- 21. UIDatePicker en PopoverView en el iPad
- 22. ¿Puedo localizar un UIDatePicker?
- 23. UITextField cambio de comportamiento de fondo de iOS 4 a iOS 5
- 24. ¿Es posible editar y recompilar un Binario de iOS?
- 25. iOS Crear teclado personalizado Generar pulsaciones de teclas estándar para UITextField
- 26. Editar .htaccess con PHP
- 27. editar XML con simpleXML
- 28. IPhone UITextField no muestra editar cursor o borrar texto de marcador de posición cuando se toca
- 29. UITextField Ejemplo en Cocos2d
- 30. iPhone SDK - UITextField con el botón + para contactos
hay un problema con este enfoque, si solo desea el marcador de fecha en la parte inferior de la pantalla, y no cubre toda la pantalla. No puede hacer que su controlador de vista presentado de forma modal sea transparente, porque las vistas subyacentes no estarán allí. http://stackoverflow.com/questions/849458/transparent-modal-view-on-navigation-controller – kris