views:

81

answers:

2

Hi , iam trying import an image from photos library but when i press the import button program crashes and received SGIBART !! but my code works fine on iPhone why ?

here is my code :

.h :

@interface CameraViewController : UIViewController <UIImagePickerControllerDelegate ,UINavigationControllerDelegate> {

    UIImagePickerController *ipc;
    UIImageView * image1;

@property (.......................;
}

.m :

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {



    image1.image = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];   

}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [[picker parentViewController]dismissModalViewControllerAnimated:YES];
    [picker release];


}



        -(IBAction) importImage1 {

    ipc = [[UIImagePickerController alloc]init];
    ipc.delegate = self;
    ipc.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:ipc animated:YES];
}
+2  A: 

You're crashing because you're releasing picker, but you didn't retain it. You should remove the calls to [picker release].

You should switch to using accessors for all of your ivars. Accessors and dealloc are generally the only places you should retain or release your ivars. picker is not your ivar and you didn't create it, so you shouldn't be releasing it at all.

You should spend some time with the Memory Management Programming Guide. You can get the short version at Three Magic Words.

Rob Napier
i removed that but doesn't work either !:(
Mc.Lover
+1  A: 

On the iPad iOS 3.2 a UIImagePickerController must be presented in a popover, not as a modal view.

check this out : http://www.cocos2d-iphone.org/forum/topic/6108

Momeks