Hour 19: Image picker must be displayed in a popover

In the MediaPlayground tutorial, the image picker MUST be presented in a popover on the iPad. This was overlooked in the text, but can be easily implemented using the techniques discussed in Hour 11: Introducing Multiple Scenes and Popovers.

To implement the popover, add a new property to ViewController.h:

@property (strong, nonatomic) UIPopoverController *popoverController

And the corresponding synthesize line to ViewController.m:

@synthesize popoverController;

And the cleanup in ViewDidUnload:

[self setPopoverController:nil];

Then change the last line in the chooseImage: method to these two statements:

popoverController=[[UIPopoverController alloc]
[popoverController presentPopoverFromRect:((UIButton *)sender).frame 
//    [self presentModalViewController:imagePicker animated:YES];

The reason for the property? ARC will deallocate the popover for us before it is ever displayed. Adding a property and corresponding instance variable ensures that ARC behaves itself.

We should also remove the line that hides the status bar, since Apple does not suggest the status bar be hidden on the iPad. To do this, simply comment out this line – also in chooseImage:

[[UIApplicationsharedApplication] setStatusBarHidden:YES];
Posted in iOS 5 Errata