Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dismiss two UIViewControllers in iOS 8?

I am working on iPhone application using Objective C. As I need to dismiss two UIViewControllers at once, so I am using below code :

[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];

This code is working fine in iOS6 and iOS7, but it is not working in iOS8. I have checked by using breakpoint, my ViewController viewDidLoad and viewWillAppear method is calling but my view is not loading at all, so as an output, I am getting blank white screen. Can anyone please help me that for iOS8, how can I solve this problem, should I need to use presentedViewController instead of presentingViewController?

like image 293
Anand Gautam Avatar asked Dec 19 '22 08:12

Anand Gautam


1 Answers

Swift code

@IBAction func goBack(sender: AnyObject) {
    var tmpController :UIViewController! = self.presentingViewController;

    self.dismissViewControllerAnimated(false, completion: {()->Void in
        println("done");
         tmpController.dismissViewControllerAnimated(false, completion: nil);
    });
}


Sample project


Objective-c code
- (IBAction)goBack:(id)sender {

    UIViewController *trmpVC = self.presentingViewController;

    [self dismissViewControllerAnimated:NO completion:^{
        [trmpVC dismissViewControllerAnimated:NO completion:nil];
    }];
}


Sample project

like image 195
Jageen Avatar answered Jan 08 '23 05:01

Jageen