【问题标题】:Presenting a modal view controller after dismissing another在关闭另一个模式视图控制器后呈现一个模式视图控制器
【发布时间】:2014-02-22 03:53:50
【问题描述】:

在用户从他们的照片库中选择一张图片后,我想关闭 imagePickerVierController 并呈现另一个,但出现错误:

警告:在演示或关闭过程中尝试从视图控制器中关闭!

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{
if (!self.submitPicturesDetailsViewController)
{
    self.submitPicturesDetailsViewController = [[SubmitPictureDetailsViewController alloc] initWithPicture: lPicture];
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
    [self.submitPicturesDetailsViewController setModalPresentationStyle:UIModalPresentationFormSheet];
    [self.popOver dismissPopoverAnimated:YES];
    [self presentViewController: self.submitPicturesDetailsViewController animated:YES completion: nil];
}else
{
    //[self performSelector:@selector(present) withObject: nil afterDelay: 5.0];
    [self dismissViewControllerAnimated:NO completion:^{
        [self presentViewController: self.submitPicturesDetailsViewController animated:YES completion: nil];
    }];
}
}

我试过了:

[self performSelector:@selector(present) withObject: nil afterDelay: 5.0];

而且它工作正常,所以显然完成块不能正常工作。

【问题讨论】:

  • 在此处查看答案,在此处回答类似问题,stackoverflow.com/a/3919894/2458651
  • @zaheer 这个答案来自 2010 年,是关于不同的 API。从 iOS5 开始,一个完成块被传递给一个新的 API,它允许链接动画。上面的代码应该工作,但没有。
  • 我自己通过创建一个虚拟项目进行了检查。有效。找不到此类问题的原因。我认为您剩下的唯一选择是调用延迟为 0.1 秒的选择器。

标签: ios objective-c uiviewcontroller presentviewcontroller


【解决方案1】:

我发现最好的万无一失的解决方案是递归调用我的方法,直到不再加载先前的视图控制器。

- (void) present
{
    if (!self.submitPicturesDetailsViewController.isViewLoaded) {
        [self presentViewController: self.submitPicturesDetailsViewController animated:YES completion: nil];
    }else{
        [self performSelector:@selector(present) withObject: nil afterDelay: 0.1];
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-03
    • 2014-12-12
    • 2016-11-20
    • 2011-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多