从相机方法调用unwind segue失败

时间:2014-07-29 23:07:16

标签: ios objective-c modal-dialog uiimagepickercontroller segue

我的unwind segue代码工作正常。我用故事板来连接起来。当我运行应用程序时,一切都很好。

但是除了点击按钮之外,我还希望从代码中解除。基本上我提出的模式包含两个按钮:相机图库。用户点击其中一个按钮可以从相机或图库中获取图像。所以一旦获得图像,我就不再需要模态视图了。因此,作为方法(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];
}

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

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

我理解这个问题。但我不知道如何解决它。

基本上我不应该打电话&#34;而#34;相机视图仍然在屏幕上(即我的模态还没有在屏幕上)。但那我在哪里打电话?是否有ImagePickerDidClose之类的东西或类似的东西?我找不到一个。所以感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

imagePickerController:didFinishPicking...方法触发时,您有机会解雇图像选择器控制器:

[picker dismissViewControllerAnimated:YES completion:nil];

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

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