I am writing an app that has an initial view containing 2 buttons – one that allows the user to take a photo with the camera and the other that allows him to select a picture from the library.
I’ve written the code that allows that to happen, but after selecting the picture, I want to go to another view that allows, say, sharing the picture or whatever. Could anyone tell me how to do something like “whenPhotoIsSelected, view = newView”?
This is my code so far:
#pragma mark -
-(IBAction) getCameraPicture: (id) sender{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = (sender == takePictureButton) ?
UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];
}
I am aware of the existence of
-(void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
but how exactly do I use it? I tried it and it crashes…
Implement the UIImagePickerControllerDelegate in your ViewController.
To do that add
<UIImagePickerControllerDelegate>to your ViewController’s interface declaration (in the .h file) like so:Then in your ViewController’s .m file you actually implement the method
-(void) imagePickerController:(UIImagePickerController *)pickerinstead of calling it, like so:didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
That method will be called by the UIImagePicker when an image was selected.