2012-04-23 126 views
0

我使用的UIImagePickerController一個小問題...我想我的實例的viewController時使用由用戶選擇的圖像從iPhone庫,並使用它:使用的UIImagePickerController檢索照片庫中選擇圖片

第一用戶必須點擊StartWithImage按鈕:

-(IBAction)startWithImage:(UIButton *) sender 
{ 
    self.imgPicker = [[UIImagePickerController alloc] init]; 
    self.imgPicker.delegate = self; 
    self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    [self presentModalViewController:self.imgPicker animated:YES]; 
} 

- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
    [imagePicker release]; 
    //UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
    photo =(UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage]; 
    //code for starting game 
} 

這是我的我的實例的viewController:

imageSliderViewController = [[ImageSliderViewController alloc] initWithSize:colMax :rowMax:photo]; 

我的看法控制器使用在viewDidLoad中喜歡這張照片:

CGImageRef cgImg = CGImageCreateWithImageInRect(photo.CGImage, CGRectMake(ox, oy, width-1, height-1));//-1 for block effect 

我得到一個EXC_BAD_ACCESS錯誤...

+0

有沒有回溯或堆棧爲貴 「'EXC_BAD_ACCESS'」 錯誤清單? – 2012-04-23 22:57:39

+0

我是一個巨大的初學者......我該如何檢查?當Xcode – Marcouss 2012-04-23 23:18:44

+0

崩潰時,我可能有一個輸出窗口(如果你沒有看到它,點擊Xcode中的「View」菜單,你會看到一個「Debug」子菜單。點擊下面的「激活控制檯」,然後,當發生崩潰時,你會看到一個「(lldb)'」提示符。輸入命令「'bt'」(不帶引號),你應該看到崩潰的位置實際發生的 – 2012-04-23 23:40:17

回答

0

好,EXC_BAD_ACCESS當對象被釋放,我們在其他地方嘗試訪問該對象通常發生。

試試這個

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

    //UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
    photo =(UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage]; 
    //code for starting game 

    // dismiss controller after working with it 
    [self dismissModalViewControllerAnimated:YES]; 
    [imagePicker release]; 
} 
相關問題