5

我想要一个全局导航堆栈。当用户改变标签或导航到同一标签中的新视图时,我想将新视图推送到全局导航堆栈上。我想要导航栏中的后退按钮返回到上一个视图,该视图有时是不同的选项卡,有时是同一选项卡中的不同视图。如何创建全局导航堆栈?

enter image description here

+1

彼得的答案(下)将工作..但这个UI听起来很“Android”。用户希望标签栏能够像标签栏一样工作......这与我以前使用的其他应用程序无关,并且会违背用户的期望(不好)。是否有另一个UI可以用来达到相同的效果? – nielsbot 2012-08-28 17:35:07

+0

也在我看来,Yelp应用程序有坏的UI,不应该用作示例:) – nielsbot 2012-08-28 17:35:55

回答

0

,你可以实现通过设置UINavigationController左侧栏按钮为您所选择的按钮一样,处理的操作方法并调用click事件相应的TabBar按钮。

你需要做的一切,在你的根视图控制器...

新增:

你坚持不下去了根视图控制器后退按钮(导航控制器; S根视图相关联与您的标签栏实例)只需按下TabBar按钮。

您需要找到实现这一目标的方法,因为您没有从iOS获取此信息因此,按下TabBar按钮的动作需要具有存储先前选定索引的变量以及提供任何信息的方法tabbar只是通过索引...因此,通过使用这两个,您可以设置导航栏的左侧栏按钮的标题,并通过将相应的操作方法分配给左侧栏按钮返回到前一个选项卡...

+0

我不明白你是什么意思? – 2012-02-14 14:37:20

+0

@ZiadTamim:查看更新后的答案.. – Jhaliya 2012-02-14 14:58:13

4

为了达到这种效果,可以放弃UITabBarController - 并通过使用自定义视图或自定义标准UIToolbar来模拟栏。

有一个导航控制器,并且您的自定义工具栏始终可见,并且在它上点击按钮时,只需将想要的视图推送到导航堆栈上即可。

+0

是的,这是标准的默认行为 – 2012-02-14 14:34:39

+0

Erm ...那么你到底有什么问题? – 2012-02-14 14:35:24

+0

我想UITabBarController中的所有UIViewController都加载到相同的UINavigationController中 – 2012-02-14 14:39:32

0

你想要将所有的UIViewControllerUITabBarController加载到同一UINavigationController

因此,像这样的:

  ___ RootViewController ___ 
     |       | 
UINavigationController  UITabBarViewController 

代替

   RootViewController 
         | 
    _________ UITabbarViewController _____________________ 
    |       |       | 
UINavigationController UINavigationController UINavigationController 

你应该尝试 “试验” 与自己的自定义UITabBar

+0

有没有任何教程或有用的东西(指南...)可以帮助我做到这一点? – 2012-02-14 14:42:28

+0

你可以创建自己的'tabbar',这只不过是一堆按钮,具有所需的'selected'状态。我一直这样做,因为我“不喜欢”默认的tabbar的UI。 – basvk 2012-02-14 14:46:06

+0

但是,如果我想提出一个模式视图控制器,UITabBar将不会被隐藏... – 2012-02-14 14:51:04

0

我建议你创建一个全局数组(NSMutableArray的)将保存NSInvocation对象。所以每次你推视图控制器时,你都需要创建一个带有导航控制器的NSInvocation作为目标,并且popViewConrollerAnimated:作为选择器。如果您点击标签栏项目,则需要将标签栏控制器设置为目标,并将setSelectedViewController:设置为选择器。你也应该每次你弹出你你只需要调用[myLastInvocation invoke]全球栈一次使用

- (void)setArgument:(void *)buffer atIndex:(NSInteger)index 

然后指定当前视图控制器参数;

0

我有类似的问题。我这样做是这样的:

要更改选项卡,使用方法:说,你想要去的接头2和第3的视图控制器

self.tabBarController.selectedIndex = 2; 

[self.tabBarController.delegate tabBarController:self.tabBarController didSelectViewController: 
    [[[self.tabBarController.viewControllers objectAtIndex:2] viewControllers] objectAtIndex:3]]; 
+0

您能解释一下您的想法吗? :) – 2012-02-14 15:16:10

0

我得到它的工作。根据我的经验,我需要将mainTabBarControllerdetailedNavigationController作为两个根控制器。 UIApplicationDelegate类工作完美的这两种方法:

- (void) showDetailedTab 
{ 
    CGRect normalRect = self.window.bounds; 
    CGRect rightRect = CGRectOffset(normalRect, normalRect.size.width, 0); 
    CGRect leftRect = CGRectOffset(normalRect, -normalRect.size.width, 0); 

    detailedNavigationController.view.frame = rightRect; 
    mainTabBarController.view.frame = normalRect; 
    [self.window addSubview:mainTabBarController.view]; 
    [self.window addSubview:detailedNavigationController.view]; 

    [UIView animateWithDuration:0.35 delay:0.0 options:UIViewAnimationCurveEaseOut 
        animations: ^{ 
         detailedNavigationController.view.frame = normalRect; 
         mainTabBarController.view.frame = leftRect; 
        } 
        completion: ^(BOOL finished){ 
         [mainTabBarController.view removeFromSuperview]; 
        }]; 
} 

- (void) showMainTabBar 
{ 
    CGRect normalRect = self.window.bounds; 
    CGRect rightRect = CGRectOffset(normalRect, normalRect.size.width, 0); 
    CGRect leftRect = CGRectOffset(normalRect, -normalRect.size.width, 0); 

    mainTabBarController.view.frame = leftRect; 
    detailedNavigationController.view.frame = normalRect; 
    [self.window addSubview:mainTabBarController.view]; 
    [self.window addSubview:detailedNavigationController.view]; 

    [UIView animateWithDuration:0.35 delay:0.0 options:UIViewAnimationCurveEaseOut 
        animations: ^{ 
         mainTabBarController.view.frame = normalRect; 
         detailedNavigationController.view.frame = rightRect; 
        } 
        completion: ^(BOOL finished){ 
         [detailedNavigationController.view removeFromSuperview]; 
        }]; 
} 

我认为这个解决方案是更好然后标签栏的模仿,因为它不会破坏UIViewContoller的生命周期。