Search code examples
iphoneiphone-sdk-3.0uipopovercontroller

Popover view notification


I have a pop over view. When this popover gets dismissed, I want to get notified.

Is there any way to do it?


Solution

  • The answer is incredibly simple!

    The delegate routine popoverControllerDidDismissPopover is called for you whenever the popover is dismissed.

    So just add this code to your code...

    -(void)popoverControllerDidDismissPopover:
            (UIPopoverController *)popoverController
        {
        NSLog(@"a popover was dismissed! thank you stackoverflow!");
        }
    

    OK? You can also use popoverControllerShouldDismissPopover if you actually want to prevent it from being dismissed.

    (Note - in the unusual case you are working with more than one popover, just check inside that routine which one it is that is being dismissed. So something like popoverController == myPostcodePopover or whatever.)

    If you don't know how to do something, the solution is almost always in the delegates available with the class you are working with.

    ----------- don't forget to do this!

    Whenever you use any delegate, of course you have to set the delegate to be "you",

    zipcodeEntryPopover.delegate = self;
    

    ----------- don't forget to do this!

    If you're going to use a delegate like that, you just need to add it to your delegate declarations where you declare the class in your .h file.

    So, in your .h file you will have something like this,

    @interface yourHappyThing : UIViewController <ASIHTTPRequestDelegate,
                        UIAccelerometerDelegate,
                        thisDelegate,
                        thatDelegate>
    

    (Often you have a large number of them in there, both system delegates and your own which you have created.) So, you just need to add the one for the popover delegate, thus ...

    @interface yourHappyThing : UIViewController <ASIHTTPRequestDelegate,
                        UIAccelerometerDelegate,
                        thisDelegate,
                        thatDelegate,
                        UIPopoverControllerDelegate>
    

    That should do it!