I have a strange problem while dismissing two modalviewcontrollers.
What I am doing is I have a viewControllers A and B. I am presentingmodalviewController B on A. And then On B I am presenting MPMediaPickerController
on B. Now my issue is After clicking on Done button in MPMediaPickerController its delegate method is calling . I have implemented the below code to dismiss the MPMediaPickerController
and Controller B,so that We can go to Controller A directly.
- (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
Any ideas or suggestions are very helpful.
Whenever you present MPMediaPickerController from a controller then you have to set its delegate to the presenting controller. So as because delegate method is inside the presenting view controller, you have to call dismissModalViewControllerAnimated instead of whatever you are doing. 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. So i just dismissed MPMediaPickerController without any animation and the presenting view controller with animation.
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
[self dismissModalViewControllerAnimated:NO];
[self.presentingViewController dismissModalViewControllerAnimated:YES];
}