我遇到了与 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
如果有人可以在这里帮助我,我将永远感激不尽!
谢谢,
斯图尔特