【问题标题】:Error: Attempt to present <UIImagePickerController: on <ViewController: while a presentation is in progress错误:在演示过程中尝试在 <ViewController: 上演示 <UIImagePickerController:
【发布时间】:2013-01-31 09:49:43
【问题描述】:

大家好,感谢您的阅读。我正在制作一个应用程序,您可以在该应用程序中拍照并从相机胶卷中检索照片并将其显示在视图上。问题是当我尝试使用调出相机胶卷的按钮时,我在标题中收到错误“演示正在进行中”。

如果我注释掉代码 [self presentViewController:imagePicker animated:YES completion:NULL];在 viewdidappear 方法中,我可以调出相机胶卷......我不知道如何正确关闭它,我试过 [imagePicker dismissViewControllerAnimated:YES completion:NULL];但无济于事。

这是我的代码!感谢您查看。

-(IBAction)chooseExisting:(id)sender {

[imagePicker dismissViewControllerAnimated:YES completion:NULL];
imagePicker2 = [[UIImagePickerController  alloc] init];
imagePicker2.delegate = self;
[imagePicker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:imagePicker2 animated:YES completion:NULL];

}

-(void)viewDidAppear:(BOOL)animated{
while (chooseExistingInt <1) {

overlayView.hidden = false;
imagePicker = [[UIImagePickerController  alloc] init];
imagePicker.delegate = self;
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:imagePicker animated:YES completion:NULL];
imagePicker.showsCameraControls = NO;
imagePicker.cameraOverlayView = overlayView;
    chooseExistingInt ++;
}
}

固定(也许)我改变了:

[imagePicker dismissViewControllerAnimated:YES completion:NULL];

[imagePicker dismissViewControllerAnimated:NO completion:NULL];

将动画更改为“否”。见鬼:s

【问题讨论】:

  • 是 UIImagePickerController UIViewController 吗?
  • [This][1] 解决方案可能会对您有所帮助。尝试在主线程 [1] 中呈现:stackoverflow.com/questions/25805643/…
  • link的可能重复
  • 除了这个帖子快2岁了

标签: ios camera uiimagepickercontroller presentation


【解决方案1】:

将您要执行的代码放在此

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//your code 
}];

【讨论】:

    【解决方案2】:

    它可以帮助你。您正在使用 presentviewcontroller 而不是 presentModalViewController

    并且在解散时也使用 dismissModalViewController

    【讨论】:

    • 谢谢你的建议,我会试试的。我收到警告,说“此方法已弃用”。这是一个问题吗?编辑:我试过这个,我得到了同样的错误:/
    • 弃用不会产生任何问题
    猜你喜欢
    • 2013-10-15
    • 2012-11-18
    • 1970-01-01
    • 2012-12-03
    • 2015-12-04
    • 1970-01-01
    • 2013-11-03
    • 2014-06-12
    • 2013-04-21
    相关资源
    最近更新 更多