2010-08-17 67 views
1

我soooooo接近終於完成我的第一個應用程序放入商店。一切工作正常,內存泄漏幾乎完全不存在....除了當我使用相機或從相機膠捲選擇圖像。iPhone UIImageView與相機或相機卷選取器內存警告級別2

如果用戶選擇相機與卷....相機工作正常...拍攝一張照片,然後當他們選擇「使用」它崩潰。相機膠捲也是如此。我是一個小菜,所以如果我搞砸了,它不會讓我感到驚訝。任何幫助/建議不勝感激...這裏是代碼:

-(IBAction) getPhoto:(id) sender { 
    UIImagePickerController * picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 

    if((UIButton *) sender == choosePhoto) { 
     picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; 
    } else { 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    } 

    [self presentModalViewController:picker animated:YES]; 
    //[picker release]; 
} 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    [picker dismissModalViewControllerAnimated:YES]; 
    theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
    [picker release]; 
} 

回答

0

您的問題可能是,由於您使用的是原始圖像,因爲它的內容類似於1400x750(不確定確切的尺寸),所以當您將它設置爲圖像視圖的圖像時,可能是內存不足顯示...您可能應該調整圖像到320x480或480x320以在圖像視圖中顯示它,這可能會解決您的問題。

+0

這是一個很好的建議。我把你的評論,並與另一個網站的另一個組合,並減少圖像的大小,並在我的班級創建一個UIImage ...設置調整大小的照片,然後將UIImageView.image屬性設置爲UIImage。所有這些似乎都會讓應用程序工作得更好。 – 2010-08-18 16:14:07

0

,在跳出我唯一的問題是UIImagePickerControllerOriginalImageNSString不變,所以你不希望把它放在引號:

theimageView.image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

但即使該行失敗,它也只會將theimageView.image設置爲nil,這可能不會導致崩潰。您應該至少在Xcode控制檯中看到更多關於崩潰的信息,這將有所幫助。另外,請查看this SO answer中的提示。

+0

感謝您的鏈接。我認爲這裏發生了許多事情,並且使它們都很好,整齊有助於它更好地運行。 – 2010-08-18 16:12:48

0

變化
[picker dismissModalViewControllerAnimated:YES];

[self dismissModalViewControllerAnimated:YES];
這應該工作

相關問題