views:

36

answers:

2

Hi!! Am new to this forum and also new to IPhone development. Following is the issue: I have two views named pickerviewcontroller and secondviewcontroller which has different xib files. I choose a picture through the UIImagePickerController interface from the Photo Library, I was trying to display the chosen image in the second view. code is here pickerController is my first view controller

pickerController.h file

#import <UIKit/UIKit.h>
#import "SecondViewController.h"

@interface pickerControllerViewController :  UIViewController<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate> {
 IBOutlet UIButton *selectpic;

UIImageView *imageView; } @property (nonatomic,retain) UIImageView *imageView; @property (nonatomic,retain) UIButton *selectpic; -(IBAction)getpic:(id)sender; //-(void)goNext: (UIImagePickerController *)picker; @end

pickerController.m fie

#import "pickerControllerViewController.h"

@implementation pickerControllerViewController
@synthesize imageView,selectpic;
-(IBAction)getpic:(id)sender
{
 UIImagePickerController *picker = [[UIImagePickerController alloc]init];
 picker.delegate = self;
 picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
 [self presentModalViewController:picker animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker  didFinishPickingMediaWithInfo:(NSDictionary *)info 
{

 imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
 [[picker parentViewController] dismissModalViewControllerAnimated:YES];
 SecondViewController *secview = [[SecondViewController alloc]initWithNibName:nil bundle:nil];
 [secview setImage:imageView];

}

SecondVIewController.h file

@interface SecondViewController :UIViewController{
 IBOutlet UIImageView *imageView2;

}
-(void)setImage:(UIImage *)image;
@end

SecondVIewController.m file

@implementation SecondViewController
-(void)setImage:(UIImage *)image{
 imageView2 = image;
}

It is not showing any error.Am not able to display the image in the secondview. please help, am struck here for the last 1 week and i could not find any solution for this...

Thanks for the help in Advance!!!!!!!!!

A: 

Create A NSData Variable in pickerControlle class and Store The Image Data in NSData

Then Pass The NSData To Next Class

Ashish Mathur
i have taken NSData type and stored the image in it and i passed the data to setImage method in second view controller.Still am not getting .
iPhoneStruggler
A: 

In firstviewcontroller.m <#import "pickerExampleViewController.h"

@implementation pickerExampleViewController @synthesize selectPic; -(IBAction)getpic:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc]init]; picker.delegate = self; picker.editing = YES; picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; [self presentModalViewController:picker animated:YES]; [picker release]; }

pragma mark imagePickerController delegate methods

-(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{ [picker dismissModalViewControllerAnimated:YES]; Second *secview = [[Second alloc] initWithNibName:@"Second" bundle:nil]; secview.view.backgroundColor = [UIColor blackColor]; [secview.imgView setImage:image]; [self.view addSubview:secview.view]; [secview release]; }

  • (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self dismissModalViewControllerAnimated:YES]; }<

In second.m you have to write <#import "Second.h"

@implementation Second @synthesize imgView;

-(void)setImage:(UIImage *)img { [imgView setImage:img];
} -(IBAction)back { [self.view removeFromSuperview]; }

-(void)dealloc { [imgView release]; [super dealloc]; } @end <

iPhoneStruggler