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:
@interface YourViewController : UIViewController <UIImagePickerControllerDelegate> {
// instance variable declarations etc.
}
Then in your ViewController's .m file you actually implement the method -(void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
instead of calling it, like so:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
// add the new view, for example you could push it on your navigation stack if you use a UINavigationController
}
That method will be called by the UIImagePicker when an image was selected.
精彩评论