Reputation: 37
In my viewDidLoad
I have the following Code:
UIDatePicker* datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker addTarget:self action:@selector(datePickerChanged:) forControlEvents:UIControlEventValueChanged];
dateField1.inputView = datePicker;
dateField2.inputView = datePicker;
dateField3.inputView = datePicker;
dateField4.inputView = datePicker;
(The dateField's are all UITextField
s)
In my -(void)datePickerChanged:(UIDatePicker*)datePicker
method, how do I know which dateField is being edited, so that I can fill in the picked date?
Currently I am using a new UIDatePicker for each UITextField, but I hope there is a more elegant solution for this situation.
Any help is appreciated!
Upvotes: 2
Views: 1386
Reputation: 764
if([textField1 isFirstResponder]) {
}
else if[textField2 isFirstResponder]){
}
...etc...
Upvotes: 8
Reputation: 1800
You can set up different tags for your dateFields and check what field was changed in datePickerChanged: method. But to do it you should store original results in another place (for example in dictionary where your dateField's tags will be a keys). I did not tried this before but should work.
Upvotes: 0