How to reject two UIViewControllers in iOS 8?

I am working on an iPhone application using Objective C. Since I need to fire two UIViewControllers at once, so I use the code below:

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

This code works fine in iOS6 and iOS7, but it does not work in iOS8. I checked with a breakpoint, my ViewController method viewDidLoad and viewWillAppear calls, but my view does not load at all, since I get a blank white screen. Can someone please help me out, that for iOS8, how can I solve this problem, should I use the presented ViewController instead of the ViewController?

+4
iphone ios8 presentmodalviewcontroller presentviewcontroller
source share
2 answers

Quick code

 @IBAction func goBack(sender: AnyObject) { var tmpController :UIViewController! = self.presentingViewController; self.dismissViewControllerAnimated(false, completion: {()->Void in println("done"); tmpController.dismissViewControllerAnimated(false, completion: nil); }); } 


Project example


Objective-c code
 - (IBAction)goBack:(id)sender { UIViewController *trmpVC = self.presentingViewController; [self dismissViewControllerAnimated:NO completion:^{ [trmpVC dismissViewControllerAnimated:NO completion:nil]; }]; } 


Project example

+10
source share

Try the following:

 NSArray *arrVC = [self.navigationController viewControllers]; [self.navigationController popToViewController:[arrVC objectAtIndex:arrVC.count-2] animated:YES]; 

Hope this helps.

+1
source share

All Articles