Modal viewController解除按钮问题

时间:2010-06-26 19:52:36

标签: iphone modalviewcontroller

我正在创建一个简单的模态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的目标方法。我肯定错过了一些明显但却没有得到的东西。有人可以帮忙吗?

提前完成。

2 个答案:

答案 0 :(得分:1)

我同意Ole的评论...另外,请确保您在dismissViewCOntroller方法中解雇它:

[self.parentViewController dismissModalViewControllerAnimated:YES];

答案 1 :(得分:1)

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