iOS 5 选项卡视图更改为推送根控制器(故事板)

发布于 2025-01-04 10:10:14 字数 874 浏览 0 评论 0原文

我有一个 uitabbarcontroller,它有 3 个项目。每个项目都有自己的导航控制器。 例如,在选项卡 1 中,用户导航到其他子视图,然后更改为选项卡 2,然后返回选项卡 1。选项卡 1 显示子视图。我如何推送根视图控制器而不是子视图? 我的 uitabbarcontroller 是定制的,并且具有:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

它是执行某种pushrootviewcontroller 的正确位置吗? 如何获得控制器?

编辑:

我已实现以下内容

UITabBarController<UITabBarControllerDelegate, UITabBarDelegate>

,并且

    -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
     {
      if (tabBarController.selectedIndex == 0)
         {
           NSLog(@"test%@",@"test");
 [self.tabBarController.selectedViewController.navigationController popToRootViewControllerAnimated:NO];
         }
      }

可以在调试器中看到 nslog 输出,但 popto root 不起作用。有什么想法吗?

i have a uitabbarcontroller which has 3 items. each item has its own navigation controller.
for example in tab 1 the user navigates to other subview and then changes to tab 2 and then back to the tab 1. the tab one shows the subview. how can i push the root view controller instead of the subview?
my uitabbarcontroller is customized and has:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

is it the right place to do some kind of pushrootviewcontroller?
how to get the controller?

edit:

i have the following implemented

UITabBarController<UITabBarControllerDelegate, UITabBarDelegate>

and

    -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
     {
      if (tabBarController.selectedIndex == 0)
         {
           NSLog(@"test%@",@"test");
 [self.tabBarController.selectedViewController.navigationController popToRootViewControllerAnimated:NO];
         }
      }

nslog output can be seen in the debugger but popto root doesnt work. any idea?

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

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

发布评论

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

评论(1

命硬 2025-01-11 10:10:14

好的,代码应该如下所示。现在它按照我想要的方式工作了。

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (tabBarController.selectedIndex == 0)
{
    if ([viewController isKindOfClass:[UINavigationController class]])
        [(UINavigationController*)viewController popToRootViewControllerAnimated:NO];
}
}

ok the code should look like this. and now it works the way i wanted.

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (tabBarController.selectedIndex == 0)
{
    if ([viewController isKindOfClass:[UINavigationController class]])
        [(UINavigationController*)viewController popToRootViewControllerAnimated:NO];
}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文