【问题标题】:How can i create a global navigation stack?如何创建全局导航堆栈?
【发布时间】:2012-02-14 14:22:03
【问题描述】:

我想要一个全局导航堆栈。当用户更改选项卡或导航到同一选项卡中的新视图时,我想将新视图推送到全局导航堆栈上。我希望导航栏中的后退按钮返回到上一个视图,有时是不同的选项卡,有时是同一选项卡中的不同视图。

【问题讨论】:

  • Peter 的回答(如下)会起作用.. 但这个 UI 听起来很“Android”。用户希望标签栏像标签栏一样工作……这与我从未使用过的其他应用程序不同,并且会违背用户的期望(不好)。是否有其他 UI 可以用来实现相同的效果?
  • 另外,在我看来,Yelp 应用程序的 UI 很糟糕,不应该用作示例 :)

标签: iphone objective-c cocoa-touch uinavigationcontroller uitabbarcontroller


【解决方案1】:

要实现此效果,您可以放弃 UITabBarController - 并通过使用自定义视图或自定义标准 UIToolbar 来模拟栏。

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

【讨论】:

  • 是的,这是标准的默认行为
  • 呃...那你到底有什么问题?
  • 我希望将 UITabBarController 中的所有 UIViewController 加载到同一个 UINavigationController 中
【解决方案2】:

您希望将UITabBarController 中的所有UIViewController 加载到同一个UINavigationController 中吗?

所以是这样的:

          ___ RootViewController ___
         |                           |
UINavigationController        UITabBarViewController

而不是

               RootViewController
                        |
     _________ UITabbarViewController _____________________
    |                           |                          |
UINavigationController   UINavigationController    UINavigationController

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

【讨论】:

  • 是否有任何教程或有用的东西(指南...)可以帮助我做到这一点?
  • 您可以创建自己的“标签栏”,它只不过是一堆具有所需“选定”状态的按钮。我一直这样做,因为我“不喜欢”默认标签栏的 UI。
  • 但是如果我想展示一个模态视图控制器,UITabBar 不会被隐藏...
  • 我没有说UITabBar 会被隐藏...只是尝试使用“默认”UINavigationController 和底部的几个UIButton 来推动@987654330 @'s to that UINavigationController。无需为此使用UITabBarController
【解决方案3】:

我建议你创建一个全局数组 (NSMutableArray) 来保存 NSI​​nvocation 对象。因此,每次推送视图控制器时,您都需要创建 NSInvocation,并将导航控制器作为目标,popViewConrollerAnimated: 作为选择器。如果您正在点击标签栏项目,您需要将标签栏控制器设置为目标并将setSelectedViewController: 设置为选择器。您还应该使用

将当前视图控制器指定为参数
- (void)setArgument:(void *)buffer atIndex:(NSInteger)index

然后每次弹出全局堆栈时,您只需调用[myLastInvocation invoke]

【讨论】:

    【解决方案4】:

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

    要更改选项卡,请使用:例如,您想进入选项卡 2 及其第三个视图控制器

    self.tabBarController.selectedIndex = 2;
    
    [self.tabBarController.delegate tabBarController:self.tabBarController didSelectViewController:
         [[[self.tabBarController.viewControllers objectAtIndex:2] viewControllers] objectAtIndex:3]];
    

    【讨论】:

    • 你能解释一下你的想法吗? :)
    【解决方案5】:

    您可以通过将UINavigationController 的左栏按钮设置为您选择的按钮来实现相同的目的,处理操作方法并在点击事件时调用相应的标签栏按钮。

    您需要在根视图控制器中完成所有这些操作...

    添加:

    您无法仅通过按标签栏按钮获得根视图控制器(导航控制器;与您的标签栏实例关联的根视图)上的后退按钮。

    您需要找到实现此目的的方法,因为您没有从 iOS 获得此功能所以您按下标签栏按钮的移动需要存储先前选择的索引的变量和提供任何标签栏信息的方法只需传递索引...因此,通过使用这两个,您可以设置导航栏左栏按钮的标题,并通过为左栏按钮分配适当的操作方法返回上一个选项卡...

    【讨论】:

    • 我没明白你的意思?
    【解决方案6】:

    我让它工作了。根据我的经验,我需要将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 的生命周期。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 1970-01-01
      • 2020-12-07
      • 2020-11-19
      • 1970-01-01
      相关资源
      最近更新 更多