if([textField1 isFirstResponder]) {
}
else if[textField2 isFirstResponder]){
}
...etc...
How to use one UIDatePicker for multiple UITextFields?
-
07-12-2021 - |
Question
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!
La solution
Autres conseils
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.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow