UIImagePickerController 的问题

发布于 2024-09-14 19:40:19 字数 2862 浏览 8 评论 0原文

我在使用presentModalViewController 呈现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

如果有人可以在这里帮助我,我将永远感激不已!

谢谢,

斯图尔特

I'm having a problem with the UIImagePickerController being presented with presentModalViewController. As soon as the view displays (be it camera or photo album), the app crashes.

The whole UI is created in code, no interface builder. This has only stopped working since I've been updating the code to run on ios4. Using leaks, I can't find any, and the total memory allocation I'm getting is around 5mb.

Here's the code that I'm using to present the camera picker -

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

And the delegates as follows -

-(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)];  
}

Setting NSZombiesEnabled to YES is telling me -

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

And the stack trace is as follows -

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

If anybody can help me out here, I would be eternally grateful!

Thanks,

Stewart

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哑剧 2024-09-21 19:40:19

我正在发布一张图像,该图像也正在自动发布。在奇怪的情况下,代码可以工作,但大多数时候它都会失败。在 3.2 中,这没有给我带来任何错误或出现,所以很可能当我仍然需要它时它没有被自动发布。大量的尝试和错误发现了它。

I was releasing an image that was also being autoreleased. On the odd occasion, the code would work, but most of the time it was falling down. In 3.2, this hadn't caused me any errors or shown up, so the chances are it wasn't being autoreleased while I was still needing it. Lots of trial and error found it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文