-2

我正在使用以下代码来关闭模式视图控制器:

- (IBAction)done {
#ifdef __IPHONE_5_0
    if ([self respondsToSelector:@selector(presentingViewController)])
        [self.presentingViewController dismissModalViewControllerAnimated:YES];
    else
#endif
        [self.parentViewController dismissModalViewControllerAnimated:YES];
}

如果我使用 iOS 4.3 iPad 运行他的模拟器,它使用self.parentViewController并且工作正常。但是,当我使用 iOS 6.0 iPad 运行模拟器时,模拟器在使用self.presentingViewController.

我没有要测试的实际 iPad……有什么想法吗?

编辑:

下面是创建模态视图控制器的代码。

NSArray* errors = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Errors" ofType:@"plist"]];

UIViewController* vc;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    DocumentsViewController_iPad* docsVC = [[DocumentsViewController_iPad alloc] initWithNibName:@"DocumentsViewController-iPad" bundle:nil];
    docsVC.documents = errors;
    docsVC.errors = YES;
    docsVC.navTitle = @"Troubleshooting";
    vc = docsVC;
} else {
    DocumentsViewController* docsVC = [[DocumentsViewController alloc] initWithNibName:nil bundle:nil];
    docsVC.documents = errors;
    docsVC.errors = YES;
    docsVC.navTitle = @"Troubleshooting";
    vc = docsVC;
}

vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:vc animated:YES];
[vc release];
4

2 回答 2

3

一些东西:

  • 是的,你应该dismissViewControllerAnimated:completion:像@rdelmar 说的那样使用
  • 你应该在presentingViewController上调用它,而不是父级
  • 您可以跳过进入演示控制器并关闭self,如果需要,它会将此消息转发给演示控制器。
于 2013-02-05T23:49:24.817 回答
1

dismissModalViewControllerAnimated: 已弃用,请改用dismissViewControllerAnimated:completion:。

于 2013-02-05T23:45:40.177 回答