1

我遇到了與呈現presentModalViewController的UIImagePickerController有關的問題。視圖顯示後(即相機或相冊),應用程序崩潰。UIImagePickerController問題

整個用戶界面是在代碼中創建的,沒有界面生成器。由於我已經更新了在ios4上運行的代碼,這隻能停止工作。使用泄漏,我找不到任何,我得到的總內存分配大約5mb。

下面是我使用呈現相機選擇器的代碼 -

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; 
[imagePicker setDelegate:self]; 
[imagePicker setAllowsEditing:YES]; 
[imagePicker setCameraCaptureMode:UIImagePickerControllerCameraCaptureModePhoto]; 
[self presentModalViewController:imagePicker animated:YES]; 
[imagePicker release]; 

和代表如下 -

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    UIImage *selectedImage = [info objectForKey:UIImagePickerControllerEditedImage]; 
    UIImage *newImage = [self createGameImage:selectedImage]; 
    [gameOptionsImageDisplay setImage:[self resizeImage:newImage toSize:CGSizeMake(95, 95)]]; 
    [self dismissModalViewControllerAnimated:YES]; 
    [mainView setFrame:CGRectMake(0, 0, 320, 480)]; 
} 

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
    [mainView setFrame:CGRectMake(0, 0, 320, 480)]; 
} 

設置NSZombiesEnabled爲YES告訴我 -

*** -[UIImage isKindOfClass:]: message sent to deallocated instance 0x142fc0 

堆棧軌跡如下 -

0 0x313f7d7c in ___forwarding___ 
1 0x3138a680 in __forwarding_prep_0___ 
2 0x3166dad2 in -[UIImageView(UIImageViewInternal) _canDrawContent] 
3 0x3166c652 in -[UIView(Internal) _didMoveFromWindow:toWindow:] 
4 0x3166c50e in -[UIView(Internal) _didMoveFromWindow:toWindow:] 
5 0x3166c50e in -[UIView(Internal) _didMoveFromWindow:toWindow:] 
6 0x3166c50e in -[UIView(Internal) _didMoveFromWindow:toWindow:] 
7 0x3166c50e in -[UIView(Internal) _didMoveFromWindow:toWindow:] 
8 0x3166aa8a in -[UIView(Hierarchy) _postMovedFromSuperview:] 
9 0x31672df6 in -[UIView(Hierarchy) removeFromSuperview] 
10 0x316d76ee in -[UITransitionView _didCompleteTransition:] 
11 0x31754556 in -[UITransitionView _transitionDidStop:finished:] 
12 0x316bc97a in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] 
13 0x316bc884 in -[UIViewAnimationState animationDidStop:finished:] 
14 0x33e487c0 in run_animation_callbacks 
15 0x33e48662 in CA::timer_callback 
16 0x313caa5a in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ 
17 0x313ccee4 in __CFRunLoopDoTimer 
18 0x313cd864 in __CFRunLoopRun 
19 0x313768ea in CFRunLoopRunSpecific 
20 0x313767f2 in CFRunLoopRunInMode 
21 0x329f36ee in GSEventRunModal 
22 0x329f379a in GSEventRun 
23 0x316692a6 in -[UIApplication _run] 
24 0x31667e16 in UIApplicationMain 
25 0x00002726 in main at main.m:14 

如果有人能幫助我,我會永遠感激!

感謝,

斯圖爾特

+0

我想了解更多關於您的視圖控制器。有一個UIImage看起來像是被雙重釋放......視圖控制器中是否有UIImage屬性? 此外,我相信你已經處理了這個,它會導致不同的錯誤信息,但你知道你不能在模擬器上使用相機?最好測試用戶的功能,否則會在iPod Touch上產生異常。 另外,你可以通過斷點確認代碼永遠不會像你的代理回調一樣嗎? – makdad 2010-08-20 00:57:55

+1

我認爲問題出在父'UIViewController'上。你說你以編程方式創建它。你能顯示代碼嗎? – 2010-08-20 01:06:51

+0

@phooze - 是的,我正在測試在顯示選項之前是否有相機可用,並且工作正常。 @ St3fan - 調用選擇器的代碼是UIViewController的一個子類,它在應用程序委託中創建並添加到窗口中。 我已經用一個新的UIViewController替換了圖像選擇器,並帶有一個漂亮的紅色背景顏色的單個UIView,並且當presentModalViewController顯示視圖時,只要它完成了在窗口中的呈現,它仍然會崩潰。呸! – hiptomorrow 2010-08-20 11:21:10

回答

2

我被釋放一個也正在自動釋放的圖像。在奇怪的情況下,代碼會起作用,但大多數情況下它正在崩潰。在3.2中,這並沒有引起我的任何錯誤或顯示出來,所以有機會在我還需要的時候沒有被自動釋放。大量的試驗和錯誤發現它。

相關問題