Search code examples
iosobjective-cdelegatesuipopovercontroller

UIPopoverController delegate not getting called on dismiss


I assign popover object o it's contentViewController and I put dismiss code in a button which resides in the content view controller.

When the button is pressed:

 [self.popover dismissPopoverAnimated:YES];

is called and popover is dismissed. However, delegate's method is not called automatically. I thought that I was not setting it's delegate, but it is there. If I add the following line after dismissPopoverAnimated line, delegate is called correctly...

 [self.popover.delegate popoverControllerDidDismissPopover:self.popover];

I don't understand why it doesn't "automatically" call the delegate's method. How can this happen?


Solution

  • The popoverControllerDidDismissPopover: in the delegate is not called when 'dismissPopoverAnimated:' is used.

    From the Apple Documentation for popoverControllerDidDismissPopover: in UIPopoverControllerDelegate:

    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.