iphone - 如何在 iOS 8 中关闭两个 UIViewController?

标签 iphone ios8 presentmodalviewcontroller presentviewcontroller

我正在使用 Objective C 开发 iPhone 应用程序。由于我需要一次关闭两个 UIViewController,所以我使用以下代码:

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

此代码在 iOS6 和 iOS7 中运行良好,但在 iOS8 中不起作用。我已经使用断点进行了检查,我的 ViewController viewDidLoad 和 viewWillAppear 方法正在调用,但我的 View 根本没有加载,因此作为输出,我得到空白屏幕。谁能帮我,对于iOS8,我该如何解决这个问题,我应该使用presentingViewController而不是presentingViewController吗?

最佳答案

Swift 代码

@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 代码

- (IBAction)goBack:(id)sender {

    UIViewController *trmpVC = self.presentingViewController;

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


Sample project

关于iphone - 如何在 iOS 8 中关闭两个 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27481756/

相关文章:

ios - 通过 BackgroundTask 在后台维护多点连接 session ?

objective-c - presentModalViewController 不显示 naviagionbar

objective-c - UIActivityViewController的completionHandler替换

ios - 如何将对对象的引用传递给导航 Controller 中包含的模态呈现的 View Controller ?

iphone - 带有一些框架的 PresentModalViewController

css - Cordova 闪屏

iphone - 我可以通过 iPhone 更改个人资料图片吗?

ios - NSUserDefaults 或 NSCache - 存储数据的最佳方式

ios - ScrollView 内的UIButton不触发 Action

ios - 位置坐标在 swift 中返回 nil