texto renombrar propiedades poner mac las hora fotos fecha editar datos cómo cambiar ios xcode uitextfield uidatepicker

ios - propiedades - renombrar fotos iphone 7



Mostrar selector de fecha en el campo de texto (3)

Soy muy nuevo en iOS, así que obviamente me faltan algunos conceptos al intentar seguir esta solución. Mostrar el selector de fechas al tocar el campo de texto para mi problema.

Tengo la interfaz y la implementación en una clase llamada DatepickerAppDelegate, pero estoy perdido aquí:

"En el XIB, Saque una barra de herramientas de la UIT y un UIDatePicker pero no lo adjunte a la vista. Conecte las salidas adecuadamente. DateChanged: responde a los cambios en el selector de fecha y doneEditing: se llama cuando el botón Hecho en la barra de herramientas haga clic. Conéctelos también. Los métodos se implementan como se indica a continuación. "

Leí algo sobre los XIB, pero estoy usando un guión gráfico, así que creo que no lo tengo entonces. Además, no estoy seguro de cómo debo sacar los elementos sin adjuntarlos a mis controladores de vista (lo estoy intentando, pero cuando suelto el botón del mouse, la herramienta vuelve a la barra de herramientas), y no lo hago. Ni siquiera entiendo por qué necesito un UIToolbar.

Y, finalmente, ¿cómo conecto mi campo de texto con el delegado del selector de fechas?

¿Alguien me puede ayudar?

ACTUALIZAR:

De hecho es muy simple, solo necesito:

datePicker = [[UIDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerModeDate; [datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged]; self.birthday.inputView = datePicker;


Agregue una vista de selector de fecha y uitoolbarview a su vista. Por ejemplo

CGFloat toolbarHeight = 44.f; CGFloat datePickerHeight = 140.f; CGFloat containerViewHeight = toolbarHeight+datePickerHeight; //create container view for datepicker and toolbar UIView *containerView = [[UIVIew alloc] initWithFrame:CGRectMake(0.f, [self.view bounds].size.height+containerViewHeight, [self.view bounds].size.width, containerViewHeight)]; //after init toolbar set the frame toolBar.frame = CGRectMake(0.f,0.f,containerView.frame.size.width, toolbarHeight]; //then add on toolbar button save and release it after add //after init datePicker set the frame datePicker.frame = CGRectMake(0.f, toolbarHeight, containerView.frame.size.width, datePickerHeight); //add datePicker and toolBar to containerView [containerView addSubview: toolBar]; [containerView addSubview: datePicker]; [toolBar release]; [datePicker release]; //add containerView to main view [self.view addSubview: containerView]; [containerView release];

Por lo tanto, cuando la vista se cargó se ocultará Y la vista de la vista está fuera del marco de tu vista.

Ahora debe asignar propiedad delegado de UITextFieldDelegate

textfield.delegate = self;

En el método de delegar textFieldDidBeginEditing, vea UITextFieldDelegate , debe UITextFieldDelegate método que mostrará su datePicker y su barra de herramientas. Si tiene muchos campos de texto para definir cuál se seleccionó, use la propiedad de etiqueta , que es un número entero y puede usar el interruptor en lugar de muchos si las condiciones.

Para mostrar el datePicker y la barra de herramientas, debe cambiar la Y del marco containerView. Aquí es cómo hacer eso.

CGRect containerViewFrame = containerView.frame; containerViewFrame.y -=containerViewHeight; containerView.frame = containerViewFrame;

Para ocultar solo más la variable containerViewHeight. Puedes usar UIViewAnimations para mostrarlo con alguna animación. Por ejemplo, UIViewAnimationCurveEaseInOut


UIResponder , de la que se hereda UITextField , define una propiedad llamada inputView . Esta propiedad (una UIView * ) puede definir una vista que se mostrará en lugar del teclado cuando esa UIResponder convierta en el primer respondedor.

Por lo tanto, si desea que aparezca un UIDatePicker cuando toca en un campo de texto (es decir, hace que ese texto sea el primer respondedor), entonces puede decir, ingenuamente:

UIDatePicker *datePicker = [[UIDatePicker alloc] init...]; ... configure datePicker ... [myTextField setInputView:datePicker];

Ahora, cuando se UITextField su UITextField , se UIDatePicker un UIDatePicker su lugar.

SIN EMBARGO

Querrás hacer más que esto, porque tendrás que manejar diferentes orientaciones y diferentes expresiones idiomáticas.

Pero esa es la idea básica.

(Y si desea una barra de herramientas sobre el UIDatePicker , para eso es la propiedad inputAccessoryView ) ...


En viewDidLoad de ViewController.m

- (void)viewDidLoad { [super viewDidLoad]; UIDatePicker *datePicker = [[UIDatePicker alloc]init]; [datePicker setDate:[NSDate date]]; datePicker.datePickerMode = UIDatePickerModeDate; [datePicker addTarget:self action:@selector(dateTextField:) forControlEvents:UIControlEventValueChanged]; [txtFieldBranchYear setInputView:datePicker]; }

Agregue un método en su ViewController

-(void) dateTextField:(id)sender { UIDatePicker *picker = (UIDatePicker*)txtFieldBranchYear.inputView; [picker setMaximumDate:[NSDate date]]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; NSDate *eventDate = picker.date; [dateFormat setDateFormat:@"dd/MM/yyyy"]; NSString *dateString = [dateFormat stringFromDate:eventDate]; txtFieldBranchYear.text = [NSString stringWithFormat:@"%@",dateString]; }

txtFieldBranchYear es una salida de UITextField