UIImagePickerController的问题

时间:2010-08-20 00:18:17

标签: iphone ios4 uiimagepickercontroller presentmodalviewcontroller

我遇到了使用presentModalViewController呈现的UIImagePickerController的问题。一旦视图显示(无论是相机还是相册),应用程序就会崩溃。

整个UI是在代码中创建的,没有界面构建器。这已经停止工作,因为我一直在更新代码以在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

如果有人可以帮助我,我将永远感激不尽!

谢谢,

斯图尔特

1 个答案:

答案 0 :(得分:2)

我发布的照片​​也是自动释放的。在奇怪的情况下,代码可以工作,但大部分时间它都在下降。在3.2中,这并没有给我带来任何错误或显示出来,所以在我还需要时它可能没有被自动释放。大量的反复试验找到了它。