[英]calling unwind segue from camera method fails
My unwind segue code is working fine. 我的unwind segue代码工作正常。 I use storyboard to wire things up.
我用故事板来连接起来。 And when I run the app, all is well.
当我运行应用程序时,一切都很好。
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
,我将我的unwind segue称为
- (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.
但我不知道如何解决它。
Basically I am not supposed to make the call "while" the camera view is still on screen (ie 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? 是否有像
ImagePickerDidClose
或类似的东西? I couldn't find one. 我找不到一个。 So thanks for any help.
所以感谢任何帮助。
When the imagePickerController:didFinishPicking...
method fires, this is your opportunity to dismiss the image picker controller as such: 当
imagePickerController:didFinishPicking...
方法触发时,这是您解除图像选择器控制器的机会:
[picker dismissViewControllerAnimated:YES completion:nil];
In most cases, when we call this line of code, we're sending nil
for the completion argument. 在大多数情况下,当我们调用这行代码时,我们将为完成参数发送
nil
。 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];
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.