I have this code which adds a UIDatepicker (datePicker) when the UITextField (dateDue) is tapped:
In the viewDidLoad:
// Initiate datepicker and assign to due date
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
[datePicker addTarget:self action:@selector(dateChanged:)
forControlEvents:UIControlEventValueChanged];
_dueDate.inputView = datePicker;
It works great, but I can't seem to get the date value in the changedDate function, it keeps returning null:
- (void) dateChanged:(id)sender{
// Add the date to the dueDate text field
NSLog(@"Date changed: %@", datePicker.date);
}
Does anyone have any idea why this is happening?
Peter