从相机方法调用 unwind segue 失败 [英] calling unwind segue from camera method fails

查看:46
本文介绍了从相机方法调用 unwind segue 失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 unwind segue 代码运行良好.我使用故事板来连接东西.当我运行应用程序时,一切都很好.

My unwind segue code is working fine. I use storyboard to wire things up. And when I run the app, all is well.

但是除了单击按钮之外,我还想从代码中展开.基本上,我展示了一个包含两个按钮的模式:相机画廊.用户单击其中一个按钮可从相机或图库中获取图像.所以一旦获得图像,我就不再需要模态视图.因此,作为方法 (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 的最后一步,我将我的 unwind segue 称为

But in addition to clicking a button, I want to also do the unwinding from code. Basically I am presenting a modal that contains two buttons: Camera, Gallery. User clicks on one of the buttons to go to either get an image from the camera or from the gallery. So once the image is obtained, I no longer need the modal view. Hence, as the last step in the method (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info, I call my unwind segue as

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  //... do work here and then
  [self performSegueWithIdentifier:@"myUnwindName" sender:self];
}

但是当我这样做时,我收到以下错误

But when I do I get the following error

attempt to dismiss modal view controller whose view does not currently appear. 
self = <UITabBarController: 0x127d09b80> modalViewController = <UIImagePickerController: 0x127e2fd80>

我明白问题所在.但我不知道如何解决它.

I understand the problem. But I don't know how to fix it.

基本上我不应该在当"相机视图仍在屏幕上时进行调用(即我的模态还没有出现在屏幕上).但是我在哪里打电话呢?是否有诸如 ImagePickerDidClose 之类的东西或类似的东西?我找不到一个.所以感谢您的帮助.

Basically I am not supposed to make the call "while" the camera view is still on screen (i.e. my modal is not on screen yet). But then where do I make the call? Is there such a thing as ImagePickerDidClose or something akin to it? I couldn't find one. So thanks for any help.

推荐答案

imagePickerController:didFinishPicking... 方法触发时,这是您关闭图像选择器控制器的机会:>

When the imagePickerController:didFinishPicking... method fires, this is your opportunity to dismiss the image picker controller as such:

[picker dismissViewControllerAnimated:YES completion:nil];

在大多数情况下,当我们调用这行代码时,我们发送的是 nil 作为完成参数.然而,如果我们想在这个解雇完成时做一些事情(就像我们在这里做的那样),我们传递一个完成块参数:

In most cases, when we call this line of code, we're sending nil for the completion argument. However, if we want to do something when this dismissal is complete (as we do here), we pass a completion block argument:

[picker dismissViewControllerAnimated:YES completion: ^{
    [self performSegueWithIdentifier:@"myUnwindName" sender:self];
}];

这篇关于从相机方法调用 unwind segue 失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆