14

I have my UIPopoverController with self as a delegate: I receive calls when I tap outside the popover controller, but when I tap inside I want to dismiss too, so I use -dismissPopoverAnimated: but delegate is not called in this case. Is this normal? Is this a bug or I am doing something wrong?

newDocPopoverController = [[UIPopoverController alloc] initWithContentViewController:vc];
[newDocPopoverController setPopoverContentSize:CGSizeMake(240, 44*4)];
[newDocPopoverController presentPopoverFromBarButtonItem:sender 
                permittedArrowDirections:UIPopoverArrowDirectionAny
                                                        animated:YES];
[newDocPopoverController setDelegate:self];

UPDATE:

Oh, regardless the origin of the problem (Whether is a bug or this is the intended behavior) calling the delegate by myself solves the problem :)

When the contentViewController's view is touched I will call parent UIPopoverController's delegate a call.

if ([parentPopoverController.delegate popoverControllerShouldDismissPopover:parentPopoverController]){
    [parentPopoverController dismissPopoverAnimated:YES];
    [parentPopoverController.delegate popoverControllerDidDismissPopover:parentPopoverController];
}r];
nacho4d
  • 43,720
  • 45
  • 157
  • 240
  • I just came across the same "problem", thanks for pointing out how to fix it; ie. dismiss the popovercontroller then call the delegate method. – Jack Jun 04 '11 at 11:02

3 Answers3

22

That's normal, expected behavior.

Quoting the Apple docs on popoverControllerDidDismissPopover::

The popover controller does not call this method in response to programmatic calls to the dismissPopoverAnimated: method. If you dismiss the popover programmatically, you should perform any cleanup actions immediately after calling the dismissPopoverAnimated: method.

Douwe Maan
  • 6,888
  • 2
  • 34
  • 35
  • Thanks!, I c. I think that info should also appear in UIPopoverController class reference also, and not only in its delegate protocol reference. ;) – nacho4d Aug 25 '10 at 15:01
22

Programmatically the popoverControllerDidDismissPopover does not get called and won't dismissed, you'll have to call the delegate yourself:

[self.PopUp dismissPopoverAnimated:YES];
[self.PopUp.delegate popoverControllerDidDismissPopover:self.PopUp];

Where PopUp is the parent UIPopoverController

Hope this helps

Cheers Al

Al Pascual
  • 1,241
  • 9
  • 7
  • this works, unfortunately it's very unintuitive. Different from the other models that use animations. For example, if you release the view in the animation it would break the app, instead here if you release the popover in the popoverControllerDidDismissPopover it will work perfectly. – Rafael Sanches Feb 11 '12 at 19:16
0

set the delegate first;

yourPopup.delegate=self;

then some where in your code (May be in Particular Method call due some event). use the following code;

[self.yourPopUp dismissPopoverAnimated:YES];

Chandramani
  • 871
  • 1
  • 12
  • 11