Ios – resignFirstResponder not working in a modal view controller

iosmodalviewcontrolleruitextfield

I'm having an issue with resigning the keyboard in a view that is shown using UIModalPresentationFormSheet. It works fine(keyboard hides) when I use UIModalPresentationPageSheet. Here is my very simple code that brings up the modal view, one in form sheet, and one in page sheet.

- (void)showModalWithFormSheet:(BOOL)formSheet {
  testViewController *test = [[testViewController alloc] initWithNibName:nil bundle:nil];
  test.modalPresentationStyle = formSheet ? UIModalPresentationFormSheet : UIModalPresentationPageSheet;
  [self presentModalViewController:test animated:YES];
  [test release]; 
}

Here is a textField delegate that resigns the responder.

- (BOOL)textFieldShouldReturn:(UITextField *)t {
  [t resignFirstResponder];
  return YES;
}

Identical code, but when presented as a formsheet, i cannot get the keyboard to hide(after resignFirstResponder is called). I tried this on both simulator and device. Any help would be appreciated, this is totally driving me insane! Its hard to believe that this question has not been brought up before, am i missing something?

Thanks

Ying

Best Answer

Answered here. Just some posts under yours.