views:

403

answers:

1

Edit:Ok, this is weird... After doing extensive debugging, I have discovered that whilst the text fields are resigning first responder status (I can see that there is no longer a blinking bar in any), the keyboard is NOT GOING DOWN! Maybe this deserves a different question.

I have several text fields in a custom uiviewcontroller subclass, which is displayed within a popover. The popover is displayed form a bar button. I want the keyboard to go down when the popover is dismissed (either by the user tapping the bar button again, or tapping outside the popover. From the view controller that displays the popover, when the popover is dismissed, in either of the 2 fashions, I call

[optionsController dismissFirstResponder];

Optionscontroller is the uiviewcontroller subclass in the popover. Dismissfirstresponder is a method I defined:

-(void)dsimissFirstResponder {
[nameField resignFirstResponder];
[descriptionField resignFirstResponder];
[helpField resignFirstResponder];

}

Those are three IBoutlets which I connected in the xib to the text fields.

That doesn't work. Any help with this would be greatly appreciated.

The code is called as such: [optionsController dismissFirstResponder]; [poppoverController dismissPopoverAnimated];

I set a breakpoint in dismissFirstResponder and it is called when I expected it to be. I also checked, and all three IBOutlets are non-nil during that function call. These are the only text fields in the whole app, so I'm not sure how else to put the keyboard down.

A: 

What you need is to receive the delegate method callbacks for a popover. Have you looked at the docs for the UIPopoverControllerDelegate? The following methods are defined:

  • -popoverControllerShouldDismissPopover:
  • -popoverControllerDidDismissPopover:

These should get called when your user does any gesture to dismiss the popover (tapping outside, etc.) assuming you've set a delegate for your popover and you've implemented this formal protocol in that delegate. When – popoverControllerDidDismissPopover: gets called, you can just call -resignFirstResponder on your controls at that point.

// In your popover delegate
- (void)popoverControllerDidDismissPopover:
                     (UIPopoverController *)popoverController
{
  [nameField resignFirstResponder];
  [descriptionField resignFirstResponder];
  [helpField resignFirstResponder];
}
Matt Long
Ahhh... I forgot that you can assign a delegate as any object... I'll assign the view controller subclass that is shown inside the popover as the delegate of the popover, and do as you say when I get back to my project, and see if it works.
Tom H
That didn't work, unfortunately. See my edit above.
Tom H