Search code examples
iosdatedatepickerdatefield

How can i make a datePicker show the date on a textField?


I have a textField in my view and under it a picker.

I need when the user chooses a date from the datePicker the textField to show the exact value of the date.

How do i get the date from the dateField?


Solution

  • Set the value_changed event of your DatePicker to a IBAction :

    example :

    - (IBAction) dateChanged:(id)sender {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        self.currentTextField.text = [dateFormatter stringFromDate:[self.datePicker date]];
    }