How to dismiss two UIViewControllers in iOS 8?

和自甴很熟 提交于 2019-12-07 11:36:20

问题


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?


回答1:


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




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!