简体   繁体   English

同时关闭两个当前的ModalViewControllers(MPMediaPickerController和UIViewController)

[英]Dismiss two present ModalViewControllers (MPMediaPickerController and UIViewController) at the same time

I have a strange problem while dismissing two modalviewcontrollers. 解雇两个modalviewcontrollers时遇到一个奇怪的问题。

What I am doing is I have a viewControllers A and B. I am presentingmodalviewController B on A. And then On BI am presenting MPMediaPickerController on B. Now my issue is After clicking on Done button in MPMediaPickerController its delegate method is calling . 我正在做的是我有一个viewControllers A和B。我在A上显示MPMediaPickerController 。然后在BI上,在B上显示MPMediaPickerController 。现在我的问题是在MPMediaPickerController中单击“完成”按钮后,它的委托方法正在调用。 I have implemented the below code to dismiss the MPMediaPickerController and Controller B,so that We can go to Controller A directly. 我实现了以下代码以关闭MPMediaPickerController和Controller B,以便我们可以直接转到ControllerA。

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{  
    [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES];
}

Same code is working for ViewControllers A, B and C but not working if third one is MPMediaPickerController 相同的代码适用于ViewController A,B和C,但如果第三个是MPMediaPickerControllerMPMediaPickerController

Any ideas or suggestions are very helpful. 任何想法或建议都非常有帮助。

Why are you using dismissModalViewControllerAnimated method ? 为什么要使用dismissModalViewControllerAnimated方法? It is deprecated, use dismissViewControllerAnimated instead. 已过时,请改用dismissViewControllerAnimated

Check with this code: 检查以下代码:

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{ 
   [self dismissViewControllerAnimated:YES completion:^{
        [[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
    }];
}

Whenever you present MPMediaPickerController from a controller then you have to set its delegate to the presenting controller. 每当您从控制器呈现MPMediaPickerController时,都必须将其代理设置为呈现控制器。 So as because delegate method is inside the presenting view controller, you have to call dismissModalViewControllerAnimated instead of whatever you are doing. 由于委托方法在呈现的视图控制器内部,因此必须调用dismissModalViewControllerAnimated而不是正在执行的操作。 I am just passing bool parameter to NO because whenever you will try to dismiss more then one viewcontroller simultaneously at that time there will be unbalanced transition call by the iOS and that may prevent another call. 我只是将bool参数传递给NO,因为每当您尝试同时解雇一个ViewController时,iOS会出现不平衡的过渡调用,这可能会阻止另一个调用。 So i just dismissed MPMediaPickerController without any animation and the presenting view controller with animation. 因此,我只是不使用任何动画就解雇了MPMediaPickerController,并使用动画来呈现视图控制器。

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{  
    [self dismissModalViewControllerAnimated:NO];
    [self.presentingViewController dismissModalViewControllerAnimated:YES];
}

have you tried the below codes? 您是否尝试过以下代码?

- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{  
    [mediaPicker dismissModalViewControllerAnimated:NO];

    [self dismissModalViewControllerAnimated:YES]; 

}

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM