2010-09-11 75 views
1

iam試圖從照片庫導入圖像,但當我按導入按鈕程序崩潰並收到SGIBART!但我的代碼在iPhone上工作正常嗎?iPad UIImagePicker問題!

這裏是我的代碼:

.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]; 
} 
+0

你表明它拋出SIGABRT,但然後說你的代碼工作正常。 「你工作得很好嗎?」是什麼意思?什麼是信號點的崩潰堆棧? – 2010-09-11 14:51:26

+0

我的作品很好,IPHONE不IPAD – 2010-09-11 16:54:34

回答

2

你崩潰,因爲你釋放選擇器,但你沒有保留它。您應該刪除對[picker release]的呼叫。

您應該切換到使用所有ivars訪問器。訪問者和dealloc通常是你應該保留或釋放你的ivars的唯一地方。選擇器不是你的伊娃,你沒有創建它,所以你不應該釋放它。

你應該花一些時間與Memory Management Programming Guide。您可以在Three Magic Words獲得簡短版本。

+0

我刪除了,但不工作!:( – 2010-09-11 16:55:06