0

大家好,我在尝试模态显示相机时遇到了崩溃。这是我的代码:

if (!imagePicker) { imagePicker = [[UIImagePickerController alloc]init]; }

[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];


[imagePicker setDelegate:self];

[self presentModalViewController:imagePicker animated:YES];

[imagePicker release];

我已经在这里进行了所有搜索,但通常只有在您拍照后才会发生崩溃

imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)info

我没有得到任何详细信息,只是应用程序关闭,我看到线程已暂停。

知道这里有什么问题。有关信息,我正在 ipod touch 3G 和 iPhone 3GS 中进行测试

4

3 回答 3

1

UIImagePickerController可能是一种痛苦。尝试

imagePicker = [[[UIImagePickerController alloc]init] autorelease];

并删除[imagePicker release];

坦率地说,我不会通过简单地测试来信任该条件分配if(!imagePicker)

于 2013-03-06T06:26:54.663 回答
0

释放它后清除 imagePicker 变量,否则当你去拍摄第二张照片并崩溃时它仍然是非空的,因为它实际上已被释放。

[imagePicker release];
imagePicker = nil;
于 2014-11-08T22:30:36.323 回答
-1

-(void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated

- (void)dismissModalViewControllerAnimated:(BOOL)animated

在 iOS 6.0 中已弃用,因此这些方法分别使用

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion

于 2013-03-06T07:01:55.343 回答