0

我正在创建一个简单的模态 ViewController。我正在创建一个带有按钮的笔尖,然后在该按钮上按下调用一个方法来显示模态 viewController,我在其中创建 viewController 和一个按钮,就像这样。

UIViewController *modalViewController = [[UIViewController alloc]initWithNibName:nil bundle:nil];
modalViewController.view.backgroundColor = [UIColor redColor];
modalViewController.;

UIButton *btnDismissViewController = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnDismissViewController.frame = CGRectMake(60, 160, 150, 50);
[btnDismissViewController setTitle:@"DISMISS" forState:UIControlStateNormal];
[btnDismissViewController addTarget:self action:@selector(dismissViewCOntroller) forControlEvents:UIControlEventTouchUpOutside];

btnDismissViewController.backgroundColor = [UIColor grayColor];
[modalViewController.view addSubview:btnDismissViewController];

[self presentModalViewController:modalViewController animated:YES];

此视图正确显示,但在按下 modalViewController 上的按钮后,不会调用关闭 modalViewController 的目标方法。我肯定错过了一些明显的东西,但没有得到什么。有人可以帮忙吗?

提前谢谢。

4

2 回答 2

1

我同意 Ole 的评论......此外,请确保您在dismissViewCOntroller类似于以下的方法中将其解雇:

[self.parentViewController dismissModalViewControllerAnimated:YES];
于 2010-06-28T03:53:10.323 回答
1

我认为您的代码中可能存在拼写错误,dismissViewCOntroller似乎应该是dismissViewController,但也许这是故意的,并且控制状态应该是UIControlEventTouchUpInside

于 2010-06-28T04:01:45.527 回答