I am currently programming an application for iOS 7, but I have recently come across an interesting error. In one of my UIViews, I have 3 normal UITextFields and two other UITextFields that resignFirstResponder when editing begins. They show a UIDatePicker and UIPickerView as well as a UIToolbar. The error I am having is when I am typing in one of the first 3 text fields, and proceed to click the textfield that ends editing without clicking the UIControl (which is called backgroundTapped:), the keyboard does not disappear. I added a log to see whether or not the text field is resigning the firstResponder status with "canResignFirstResponder", and it is returning "1", yet the keyboard does not disappear, even when changing views until I click one of the top 3 text fields and click the background.
Here is my textFieldDidBeginEditing: and the start of my showRunTypePicker: methods:
textFieldDidBeginEditing:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[textField becomeFirstResponder];
if (textField.tag == 3005) {
//[textField resignFirstResponder];
//[self.view endEditing:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
[self showRunTypePicker:self];
[UIView commitAnimations];
}
}
showRunTypePicker:
- (IBAction)showRunTypePicker:(id)sender
{
BOOL canResign = [runTypeField canResignFirstResponder];
NSLog(@"canResign: %hhd", canResign);
[runTypeField endEditing:YES];
[runTypeField resignFirstResponder];
[[self view] endEditing:YES];
[pickerView endEditing:YES];
[pickerView setHidden:YES];
[toolbar setHidden:YES];
[distanceField endEditing:YES];
...
}
I cannot seem to figure out what the problem is. Can anyone help me on this?
EDIT: It's working now. I set the [self showRunTypePicker:self] to [self showRunTypePicker:textField] and moved it to textFieldShouldBeginEditing. Now the keyboard properly disappears.