如何将新的视图控制器推送到不同的导航控制器堆栈并切换到它?

发布于 2024-08-28 18:42:09 字数 245 浏览 4 评论 0原文

我在 Interface Builder 中创建了一个选项卡栏控制器,

选项卡栏中有 4 个导航控制器。

每个控制器都单独且完美地运行(耶!)

我需要做的是将视图控制器推送到不同的导航控制器堆栈上,并将焦点切换到适当的选项卡栏项目上(以便用户侧向移动(到不同的选项卡)并同时向上(到新视图)。

这是我第一次使用标签栏控制器,虽然到目前为止很简单,但弄清楚这一点让我很舒服。如果您能向我提出任何建议,我将不胜感激。

I have a Tab Bar Controller created in Interface Builder

Within the Tab Bar are 4 Navigation Controllers.

Each controller functions separately and perfectly (yay!)

What I need to be able to do is a push a view controller onto a different nav controllers stack and switch the focus onto the appropriate tab bar item (so that the user moves sideways (to a different tab) and up (to a new view) at the same time).

This is my first time working with a tab bar controller, and while it's been simple to this point, figuring this out is giving me fits. Any tips you can toss my way would be much appreciated.

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

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

发布评论

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

评论(1

撩动你心 2024-09-04 18:42:09

我将使用类似以下内容作为起点,其中 whichTab 是您将推送到的选项卡的索引,而 newViewController 是您要推送的视图控制器并切换到。您可能需要尝试一下推送与切换的顺序。

UITabBarController *tabBarController = (UITabBarController *)[[[UIApplication sharedApplication] delegate] tabBarController];

UINavigationController *otherNavController = (UINavigationController *)[[tabBarController viewControllers] objectAtIndex:whichTab];

[otherNavController pushViewController:newViewController animated:NO];
tabBarController.selectedIndex = whichTab;

I would use something like the following as a starting point, where whichTab is the index of the tab you will be pushing onto, and newViewController is the view controller you want to push and switch to. You may need to play around with the ordering of pushing versus switching.

UITabBarController *tabBarController = (UITabBarController *)[[[UIApplication sharedApplication] delegate] tabBarController];

UINavigationController *otherNavController = (UINavigationController *)[[tabBarController viewControllers] objectAtIndex:whichTab];

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