Reputation: 2434
I have view controller that contains three UITextFields called "Name", "Location" and "Birthday".
I have this code here which opens a UIDatePicker:
// Open date picker
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Make a new view, or do what you want here
UIDatePicker *pv = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,245,0,0)];
[self.view addSubview:pv];
return NO;
}
Here I have two problems.
Problem 1
When I tap any field the datepicker opens. I just want to open the datepicker when "Birthday" is tapped.
Problem 2
When I tap on a field, then tap again, it opens another datepicker.
How can I stop this from happening?
Peter
Upvotes: 1
Views: 2974
Reputation: 1801
For opening the datepicker only for a specific textField, check the (UITextField *)textField
before opening datePicker. You can set tags to each textField and then use that tag to differentiate.
For your second issue, you need to use resignFirstResponder
Upvotes: 1
Reputation: 6918
Instead try this on viewDidLoad:
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
birtdayTextField.inputView = datePicker; //birtdayTextField is your "birthday text field"
Upvotes: 5