我正在使用 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);
});
}
<小时/>
Objective-c 代码- (IBAction)goBack:(id)sender {
UIViewController *trmpVC = self.presentingViewController;
[self dismissViewControllerAnimated:NO completion:^{
[trmpVC dismissViewControllerAnimated:NO completion:nil];
}];
}
关于iphone - 如何在 iOS 8 中关闭两个 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27481756/