添加视图按钮不起​​作用

发布于 2024-10-06 22:49:55 字数 991 浏览 7 评论 0原文

我在 Test1ViewController.m 中推送 test2ViewController,

Test2ViewController *test2ViewController = [[Test2ViewController alloc] initWithNibName:@"Test2ViewController" bundle:nil];
[self.navigationController pushViewController:test2ViewController animated:YES];

在 Test2ViewController.m 中,我插入一个子视图 test3ViewController,

Test3ViewController *test3ViewController = [[Test3ViewController alloc] initWithNibName:@"Test3ViewController" bundle:nil];
[self.view addSubview:test3ViewController.view];

我的问题,我想在 test3ViewController 中推送一个新视图(test4ViewController),但是 test3ViewController.view 中的按钮操作不起作用

-(IBAction) goButtonAction:(id) sender {
    Test4ViewController *test4ViewController = [[Test4ViewController alloc] initWithNibName:@"Test4ViewController" bundle:nil];
    [self.navigationController pushViewController:test4ViewController animated:YES];
}

似乎 test3ViewController不在导航流程中,如何在插入视图上推送新视图?

I push test2ViewController in Test1ViewController.m,

Test2ViewController *test2ViewController = [[Test2ViewController alloc] initWithNibName:@"Test2ViewController" bundle:nil];
[self.navigationController pushViewController:test2ViewController animated:YES];

in Test2ViewController.m, I insert a subview test3ViewController,

Test3ViewController *test3ViewController = [[Test3ViewController alloc] initWithNibName:@"Test3ViewController" bundle:nil];
[self.view addSubview:test3ViewController.view];

my question, I wanna push a new view (test4ViewController) in test3ViewController, but the button action in test3ViewController.view does not work

-(IBAction) goButtonAction:(id) sender {
    Test4ViewController *test4ViewController = [[Test4ViewController alloc] initWithNibName:@"Test4ViewController" bundle:nil];
    [self.navigationController pushViewController:test4ViewController animated:YES];
}

It seem that the test3ViewController is not in navigation flow, how can I push a new view on a insert view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

泪眸﹌ 2024-10-13 22:49:55

test3ViewController 从未添加到 navigationController 的堆栈中。如果您想推送 test4ViewController,那么您必须从 test2ViewController 执行此操作,或者使用 UINavigationController 的 setViewControlers:animated: 方法将 test3ViewController 添加到堆栈中:

NSMutableArray *array = [NSMutableArray arrayWithArray:test2ViewController.navigationController.viewControllers];
[array addObject:test3ViewController];
[test2ViewController.navigationController setViewControllers:array animated:NO];
[test2ViewController.navigationController popToViewController:test3ViewController animated:NO];

test3ViewController was never added to the stack for the navigationController. If you want to push test4ViewController, then you will have to either do it from test2ViewController, or use the setViewControlers:animated: method of UINavigationController to add test3ViewController to the stack:

NSMutableArray *array = [NSMutableArray arrayWithArray:test2ViewController.navigationController.viewControllers];
[array addObject:test3ViewController];
[test2ViewController.navigationController setViewControllers:array animated:NO];
[test2ViewController.navigationController popToViewController:test3ViewController animated:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文