Objective-c 代码
我正在使用Objective C开发iPhone应用程序。由于我需要一次关闭两个UIView控制器,所以我使用以下代码:
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
此代码在 iOS6 和 iOS7 中运行良好,但在 iOS8 中不起作用。我已经使用断点进行了检查,我的视图控制器视图DidLoad和viewWillAppear方法正在调用,但我的视图根本没有加载,因此作为输出,我得到空白的白屏。任何人都可以帮助我,对于iOS8,我该如何解决这个问题,我是否需要使用presentViewController而不是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];
}];
}
示例项目
尝试以下操作:
NSArray *arrVC = [self.navigationController viewControllers];
[self.navigationController popToViewController:[arrVC objectAtIndex:arrVC.count-2] animated:YES];
希望这有帮助。