开发者

UIImagePicker in one view, send selected image to a second view

In my main view controller I have a button that prompts the user to select a photo from their photo library then display it (img), which looks like this:

-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
[picker release];}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
img.image = [info objectF开发者_Python百科orKey:@"UIImagePickerControllerOriginalImage"];}

My question is how can I also display this selected image in a second view controller? I know how to go to a different view, I'm just unsure how to send an image to that view.


Take this in .h file in SecondViewController

UIImage *imgSelected;

Make below function in seconviewcontroller

-(void)setImage:(UIImage *)imgCaptured{
    imgSelected=imgCaptured;
}

Now In first view controller do like this:

SecondViewControler *objSecond = [[SecondViewController] initwithNibName:@"secondview.xib" bundle:nil];

[objSecond setImage:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];
[self.navigationController pushViewController:objSecond animated:YES];
[objSecond release];

Please check spelling mistakes as I hand written this. Hope this help.


If the view controller has been instantiated already i.e. it is below the current view controller in the navigation stack, you can consider delegates or notifications.

If it is yet to be created then save the image in an instance variable and pass it along when you push the next view controller.


example


firstviewcontroller .h file

        before @interface 

        use @class secondViewcontroller;


declare this inside of @interface  with

        secondViewcontroller *sVC;


then in firstViewController.m file 

        before @implementation

        use 

    #import "secondViewcontroller.h"


then




-------------------

secondVC.h file

        @interface inside declare this

        say UIImage *secondimage;

        and sythasize them.








-------------------


after this 

        in firstViewcontroller.h viewdidload create this sVC by alloc and initwithnibname then

        sVC.secondimage=urfirstImage;

        now while u push this sVC controller to navigation controller u can show that in UIImageView.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜