【问题标题】:UITabBarController with UINavigationController带有 UINavigationController 的 UITabBarController
【发布时间】:2023-04-02 04:33:01
【问题描述】:

我在 UITabBarController(选项卡 1)中有一个 UINavigationController。当我进入第二个视图(仍在选项卡 1 中)时,如何使选项卡栏消失?我可以使用返回按钮向后导航,标签栏将重新出现。

【问题讨论】:

    标签: iphone objective-c xcode ios


    【解决方案1】:

    self.hidesBottomBarWhenPushed=YES; 将此行放在您导航的位置(在推送操作之前)。

    和 self.hidesBottomBarWhenPushed=NO; 在 viewWillDisappear 从您推送其他视图的同一页面中消失。

    确实有效。

    【讨论】:

    • @Adele 如果它适合你,那么为什么不接受它。以及你所说的 self 导航控制器是什么意思。
    • 在将另一个 VC 推送到导航控制器时将 .hidesBottomBarWhenPushed 设置为 self 不会做任何事情,您需要在被推送的 VC 上进行设置。
    • 它一直对我很好。假设我想在点击表格视图的一行时打开一个新视图@Nick Forge,然后在推送之前在 didSelectRow 和 viewWillDissapear 中使用此语句设置到 no.so 在下一个视图中,我找到标签 hihe,当我回到同一个位置的上一个视图标签时。
    【解决方案2】:

    在被推送的viewController中,放:

    self.hidesBottomBarWhenPushed = YES;
    

    -viewDidLoad 方法中。它属于“子”VC,而不是进行推送的 VC。您无需在其他任何地方设置它。

    【讨论】:

      【解决方案3】:

      我喜欢使用视图控制器的 init 方法来隐藏底部栏,等等。更好地封装行为。

      (注意:以下是 ARC 友好的代码,因此没有 autorelease 调用或 retain/release 对。)

      #pragma mark - UIViewController
      
      - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
          // We must handle this as it's the designated initializer for UIViewController.
          // Pay no attention to the params. We're going to override them anyway.
          return [self init];
      }
      
      #pragma mark - NSObject
      
      - (id)init {
          // Why hello there, superclass designated initializer! How are you?
          if ((self = [super initWithNibName:@"YourNibNameHere" bundle:nil])) {
              // This is a perfect oppy to set up a number of things, such as ...
      
              // ... the title (since you're in a nav controller).
              self.navigationItem.title = @"Your Nav Title";
      
              // ... your bottom bar hiding (takes effect once pushed onto your nav controller).
              self.hidesBottomBarWhenPushed = YES;
      
              // ... and your tab bar item (since you're in a tab bar controller).
              [self setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"Item Title" image:[UIImage imageNamed:@"itemIcon.png"] tag:itemTag]];
          }
          return self;
      }
      

      现在你要做的就是alloc/init你的视图控制器并调用-pushViewController:animated:。没有麻烦,没有大惊小怪。

      当弹出 VC 时,您的底栏返回。 (承诺。)

      这项技术的功劳归功于 Big Nerd Ranch 的 Joe Conway。 (我就是从他那里学到了这个绝妙的模式。)

      至于使用点符号还是不使用,那是完全不同的讨论。 YMMV。 ;)

      【讨论】:

        猜你喜欢
        • 2012-10-13
        • 2013-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-31
        • 2010-11-24
        • 2019-03-03
        • 1970-01-01
        相关资源
        最近更新 更多