O'Reilly logo

Programming iOS 4 by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing a Popover

Unlike the controller of a modal view or of a view used in a tab bar interface or a navigation interface, a UIPopoverController instance is not automatically retained for you; you must retain it manually. You’ll need a reference to any UIPopoverController that you present, because without such a reference you can’t do two things you’re likely to want to do afterward:

Dismiss the popover
There are two ways in which a popover can be dismissed: the user can tap outside the popover, or you can explicitly dismiss the popover (as I do with the first popover in Figure 22-1 when the user taps the Done button or the Cancel button). In order to dismiss the popover explicitly, you send its UIPopoverController the dismissPopoverAnimated: message. But you can’t do that unless you have a reference to that UIPopoverController.
Release the popover
Because you created the UIPopoverController with alloc, you’re eventually going to want to send it a release message. But you can’t release a UIPopoverController while its popover is showing. Thus, you’re going to want to release the UIPopoverController after its popover has been dismissed. But you can’t do that unless you have a reference to that UIPopoverController.

Nor do the complications of popover management end there. In keeping with the transient nature of popovers, I like to dismiss the current popover programmatically when the application undergoes certain strong transitions, such as going into the background or being rotated. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required