I am presenting a view controller as a modal. This view controller has several UITextFields connected via IB.
My issue is when hitting the return key, the delegate method is called, but for some reason the call to resignFirstResponder on the given textField is not. Even if I print a message to the console in the textFieldShouldReturn delegate method it gets printed, but it will simply refuse to call the resign method.
In the shouldReturn delegate method I only have:
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
This has really never happened to me before, it just simply will not resignFirstResponder. As I mentioned before, I can place a print to console, just to verify that the shouldReturn method gets called and it does.
I also tried this just to see if the delegate was been set or not and it sure made the change to the UITextField behavior.
-(void)textFieldDidBeginEditing:(UITextField *)textField {
[textField setTextAlignment:UITextAlignmentCenter];
}
This issue truly baffles me. Even when I attempt to call resignFirstResponder on the textfield directly it won't dismiss the keyboard.
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
if ([textField isEqual:self.productTextField]) {
NSLog(@"Product textfield");
[self.productTextField resignFirstResponder];
} else if ([textField isEqual:self.quantityTextField]) {
NSLog(@"Quantity textfield");
}
return YES;
}
Both logs work with their respective textfields and print their corresponding messages each. But calling the method still does nothing when messaging the textfield directly.
Found the answer, apparently, UIPresentationFormSheet does not allow you to get rid of the keyboard. I tried with a different presentation style and it worked. @Cal, thanks for your question.