标签栏在屏幕底部下方消失 [英] Tab Bar disappears below the bottom of the screen

查看:30
本文介绍了标签栏在屏幕底部下方消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用导航控制器来推送一个加载标签栏控制器和自定义导航栏的视图.问题是Tab Bar在屏幕底部下方消失了,不知道是什么原因造成的.

In my application I'm using a Navigation Controller to push one view that loads a Tab Bar Controller and a custom Navigation Bar as well. The problem is that the Tab Bar disappears below the bottom of the screen, and I don't know what's causing the problem.

如果我在下一个视图中加载一个简单的 Tab Bar,它会正确定位自己……但我需要的是 Tab Bar Controller,在这种情况下,Tab Bar 会消失在底部下方.我曾尝试更改 Tab Bar 的视图和大小属性,但这并没有解决问题.

If I load a simple Tab Bar in the next view, it positions itself correctly... but what I need is a Tab Bar Controller, and in that case the Tab Bar disappears below the bottom. I have tried changing the view and size properties of the Tab Bar, but that did not solve the problem.

我还意识到标签的图像和文本没有显示(我已经设置了收藏夹"和联系人"图像和文本,它们足够大,应该在顶部可见标签,但它们不是).

I also realised that the images and text of the tabs don't show (I have set up the "favourites" and "contacts" images and text, and they are big enough and should be visible on the top side of the tab, but they are not).

顺便说一下,这两个选项卡都运行良好.

Both tabs work perfectly, by the way.

这里有一个图片.

我使用以下代码加载标签栏:

I load the Tab Bar with the following code:

- (void)viewDidLoad {
    [super viewDidLoad];
    myTabBarController = [[UITabBarController alloc] init];
    SettingsViewController* tab1 = [[SettingsViewController alloc] init];   
    AboutViewController* tab2 = [[AboutViewController alloc] init];
    NSArray* controllers = [NSArray arrayWithObjects:tab1, tab2, nil];
    myTabBarController.viewControllers = controllers;
    [self.view insertSubview:myTabBarController.view belowSubview:myNavigationBar];
}

我是否删除导航栏并不重要.我已经使用它进行了测试:

It doesn't matter if I remove the Navigation Bar or not. I have tested using this instead:

[self.view addSubview:myTabBarController.view];

...忘记导航栏,但标签栏仍然在底部.

... forgetting about the Navigation Bar, but the Tab Bar still goes under the bottom.

我不知道问题是出在我的一个 NIB 文件中还是出在我加载视图的方式上(尽管我在 Apple 的 SDK 文档中读到了这一点).有什么想法吗?

I don't know if the problem is in one of my NIB files or in how I load the view (although I do this as I read in the Apple's SDK documentation). Any ideas?

另一个问题是...您知道如何在选择第二个选项卡时更改导航栏的标题吗?我想我必须在 AboutViewController.m 中的 viewDidLoad 中执行此操作,对吗?

Another question would be... do you know how could I change the title of my Navigation Bar when I select the second tab? I imagine I would have to do it in viewDidLoad in AboutViewController.m, would that be correct?

感谢您的时间!

推荐答案

请在每次提交时提出一个问题 - 这将使我们能够更好地帮助您.

Please ask one question per submission - it will allow us to better help you.

对于您的第一个问题:您需要将标签栏控制器添加到导航控制器,而不是该视图.层次结构应该是:

For your first problem: you need to add the tab bar controller to the navigation controller, not to that view. The heirarchy should be:

  • 导航控制器
    • 标签栏控制器
      • 您的观点

      (尽管 Apple 的文档建议标签栏应该是应用程序范围的,因此应该是根视图,而不是导航控制器).

      (Though Apple's documentation suggests that the tab bar should be application-wide and should thus be the root view, not the navigation controller).

      对于您的第二个问题,返回"按钮上的文本由前一个视图控制器的 title 属性决定.要更改它,请执行以下操作(source):

      For your second question, the text on the "Back" button is determined by the title property of the previous view controller. To change it, do the following (source):

      - ( void )viewDidLoad
      {
          [ super viewDidLoad ];
      
          UIBarButtonItem *backButton =
          [[ UIBarButtonItem alloc ] initWithTitle:@"Back"
                                             style:UIBarButtonItemStyleBordered
                                            target:nil
                                            action:nil ];
          self.navigationItem.backBarButtonItem = backButton;
          [ backButton release ];
      }
      

      您似乎想在导航堆栈中设置第二个视图控制器的标题.这很简单:

      It appears you want to set the title of the second view controller in your navigation stack. That's easy:

      - ( void )viewDidLoad
      {
          [ super viewDidLoad ];
      
          self.title = @"Title";
      }
      

      这篇关于标签栏在屏幕底部下方消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆