1

有没有人见过这个?在 iPad 模拟器中,我有一个 About 视图控制器。我想以模态方式呈现它,并让用户单击关闭按钮。

更复杂的是,我有一个主视图控制器,它显示一个 iAd 横幅和一个“主菜单”视图控制器。该按钮位于主菜单上,因此 IBAction 被发送到主菜单视图控制器。

在主菜单 VC 中,我有一个指向应用程序视图控制器的属性,所以我调用:

AboutViewController *about = [[AboutViewController alloc] initWithNibName:....];
about.callingViewController = viewController;
[viewController presentViewController:about animated:YES completion:nil];

那么在 About View Controller 中,我有一个 IBAction 将其关闭:

- (void) dismissAbout:(id)sender
{
    [callingViewController dismissViewControllerAnimated:YES completion:nil];
}

当调用 dismissAbout 时,什么也没有发生——视图没有消失,调试器控制台中也没有输出。有任何想法吗?

4

3 回答 3

3

我想你需要打电话

[self dismissViewControllerAnimated:YES completion:nil];

反而。

于 2013-04-17T21:24:36.907 回答
2

IBAction 应该是

- (IBAction) dismissAbout:(id)

其次,您正在取消 aboutController 所以应该使用self而不是callingViewController

于 2013-04-17T21:24:58.743 回答
0

As the other answers say, you can use [self dismiss...] because that message is automatically forwarded to the presenting view controller. You also could use [self.presentingViewController dismiss..] because a modal controller has a presentingViewController property that points to the view controller that presented you. There's no need to create and pass the callingViewController.

于 2013-04-17T21:38:01.323 回答