模态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 的目标方法。我肯定错过了一些明显的东西,但没有得到什么。有人可以帮忙吗?
提前致谢。
I'm creating a simple modal ViewController. I'm creating a nib with a button and on that button press calling a method to display modal viewController in which I'm creating the viewController and a button inside it like this.
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];
This view is appearing properly but after pressing the button on modalViewController, the target method for dismissing the modalViewController isn't called. I'm definitely missing something obvious but not getting what. Can anybody please help?
Thanx in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同意 Ole 的评论...此外,请确保您在类似于以下的
dismissViewCOntroller
方法中忽略它:I agree with Ole's comment... additionally, make sure you are dismissing it within your
dismissViewCOntroller
method similar to this:我认为您的代码中可能存在拼写错误,
dismissViewCOntroller
看起来应该是dismissViewController
,但也许这是故意的,控件状态应该是UIControlEventTouchUpInside< /代码>。
I think there might be a typo in your code,
dismissViewCOntroller
seems like it should bedismissViewController
, but maybe that was intentional, and the control state should beUIControlEventTouchUpInside
.