Graphics Programs Reference
In-Depth Information
But, oops - you dismissed the controller without keeping a reference to the image any-
where in the code. To hold on to the selected image, you need to implement the delegate
method imagePickerController:didFinishPickingMediaWithInfo: in
DetailViewController .
But before you implement this method, let's take care of the two warnings that appeared
during the last build telling you that DetailViewController does not conform to
the UIImagePickerControllerDelegate or the UINavigationControl-
lerDelegate protocol. In DetailViewController.h , add the protocols to the
class declaration. (Why UINavigationControllerDelegate ? UIImagePick-
erController is a subclass of UINavigationController .)
@interface DetailViewController : UIViewController
<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
That's better. Notice that the two warnings have gone away.
The imagePickerController:didFinishPickingMediaWithInfo: mes-
sage will be sent to the image picker's delegate when a photo is selected. In De-
tailViewController.m , implement this method to put the image into the
UIImageView that you created earlier.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Get picked image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Put that image onto the screen in our image view
[imageView setImage:image];
// Take image picker off the screen -
// you must call this dismiss method
[self dismissViewControllerAnimated:YES completion:nil];
}
Build and run the application again. Take a photo, the image picker is dismissed, and you
are returned to the DetailViewController 's view . Do you see your image? Oddly
enough, you might or you might not. Let's figure out what's going on and fix the problem.
When a photo is taken, that image is loaded into memory. However, the image file is so
large that it causes a low-memory warning. Recall that a low-memory warning gives the
system the option of requiring view controllers to release their views if they are not cur-
rently visible. When a modal view controller is on the screen, its view is visible, and the
Search WWH ::




Custom Search