0

i have view controller which contains a button which show the image library ,if the user tap the image,the select image will display in the same view with the button ,but i want to show this image in another class ?(view controller).my code is

-(IBAction) getPhoto:(id) sender {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIButton *) sender == choosePhotoBtn) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    }   
    [self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

it shows the image in the same view,but my need is to show it in another view.How to dod this.

stackiphone
  • 1,245
  • 3
  • 19
  • 41
  • Just pass the imageView.image to the viewController to where you want show the image – Bala Mar 23 '12 at 06:47

1 Answers1

0

Store the Image in a UIImage object and pass it to the viewController you want

In your Current View Controller

.h declare the a UIImage object

UIImage *selectedImage;

In .m file

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
   selectedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    imageView.image = selectedImage;
}

Pass it to the viewController you want

YourViewController *viewObj = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:[NSBundle mainBundle]];
viewObj.imageToBePassed = selectedImage;
//You should synthesize this object imageToBePassed
[self viewObj animated:YES];
[viewObj release];
ipraba
  • 16,485
  • 4
  • 59
  • 58
  • hii,u r correct,but there is a problem in navigation [picker dismissModalViewControllerAnimated:YES]; it will show the sameviewcontroller after selection of image from library, – stackiphone Mar 23 '12 at 07:01
  • you can even pass the imagePath and retrive that from other controller http://stackoverflow.com/a/4314524/1059705 – Bala Mar 23 '12 at 07:13
  • @WhySoSerious i for this error while adding this code YourViewController *viewObj = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:[NSBundle mainBundle]]; viewObj.imageToBePassed = selectedImage; //You should synthesize this object imageToBePassed [self viewObj animated:YES]; [viewObj release]; "incompatible pointer type assining to UIImageView From UIImage – stackiphone Mar 23 '12 at 07:14
  • @stackiphone you are assigning a UIImage to a UImageView.. imageToBePassed is a UIImage not a UIImageView – ipraba Mar 23 '12 at 07:21