views:

185

answers:

1

Hello guys, I 'm new to xcode. I try to select an image from the UIImagePickerController and then display this image pressing a button. But the simulator crashes. In the .h I use UIImage *dispimage; //in order to make a global image -(IBAction) open; -(IBAction) print;

In the .m I have - (void)viewDidLoad { self.imgPicker = [[UIImagePickerController alloc] init]; self.imgPicker.allowsImageEditing = YES; self.imgPicker.delegate = self; self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

} - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { dispimage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES]; }

-(IBAction) open{ UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; [self presentModalViewController:imagePicker animated:YES]; [imagePicker release]; }; -(IBAction) print{ imageView.image=dispimage; };

When the button "print" is pressed, the sdk crashes. :( Any help would be appreciated

Thanks in advance

A: 

Here is the code to get images from UIImagePickerController

-(void)viewDidLoad 
{
     self.imgPicker = [[UIImagePickerController alloc] init]; 
     self.imgPicker.allowsImageEditing = YES;
     self.imgPicker.delegate = self; 
     self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
     dispimage = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
     [picker dismissModalViewControllerAnimated:YES]; 
}

-(IBAction)open
{
    if(self.imgPicker == nil)
    { 
         self.imgPicker = [[UIImagePickerController alloc] init]; 
         self.imgPicker.allowsImageEditing = YES;
         self.imgPicker.delegate = self; 
         self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    [self presentModalViewController:self.imagePicker animated:YES]; 
    [self.imagePicker release]; 
}

-(IBAction) print
{ 
      if(dispimage != nil)
      {
            imageView.image=dispimage; 
      }
};
Jim
Thank you very much, for your quick and correct answer..