模态viewController关闭按钮问题

发布于 2024-09-07 07:57:30 字数 996 浏览 3 评论 0原文

我正在创建一个简单的模式 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

棒棒糖 2024-09-14 07:57:30

我同意 Ole 的评论...此外,请确保您在类似于以下的 dismissViewCOntroller 方法中忽略它:

[self.parentViewController dismissModalViewControllerAnimated:YES];

I agree with Ole's comment... additionally, make sure you are dismissing it within your dismissViewCOntroller method similar to this:

[self.parentViewController dismissModalViewControllerAnimated:YES];
冰葑 2024-09-14 07:57:30

我认为您的代码中可能存在拼写错误, dismissViewCOntroller 看起来应该是 dismissViewController,但也许这是故意的,控件状态应该是 UIControlEventTouchUpInside< /代码>。

I think there might be a typo in your code, dismissViewCOntroller seems like it should be dismissViewController, but maybe that was intentional, and the control state should be UIControlEventTouchUpInside.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文