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?
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);
});
}
Objective-c code
- (IBAction)goBack:(id)sender {
UIViewController *trmpVC = self.presentingViewController;
[self dismissViewControllerAnimated:NO completion:^{
[trmpVC dismissViewControllerAnimated:NO completion:nil];
}];
}
Try following:
NSArray *arrVC = [self.navigationController viewControllers];
[self.navigationController popToViewController:[arrVC objectAtIndex:arrVC.count-2] animated:YES];
Hope this helps.
来源:https://stackoverflow.com/questions/27481756/how-to-dismiss-two-uiviewcontrollers-in-ios-8