无法在TabBarViewController中向UINavigationBar添加按钮或标题

时间:2014-07-07 04:00:03

标签: ios uinavigationcontroller uitabbarcontroller uinavigationbar

我在UINavigationController内有UITabBarController

导航控制器中的viewDidLoad如下所示:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationBar.barTintColor = [UIColor blueColor];
    self.navigationBar.translucent = NO;

    self.navigationBar.topItem.title = @"HOME";
    self.navigationItem.title = @"HOME"; // Neither works

        // create three funky nav bar buttons
    UIBarButtonItem *one = [[UIBarButtonItem alloc]initWithTitle:@"One" style:UIBarButtonItemStylePlain target:self action:@selector(testMethod)];
    UIBarButtonItem *two = [[UIBarButtonItem alloc]initWithTitle:@"Two" style:UIBarButtonItemStylePlain target:self action:@selector(testMethod)];
    UIBarButtonItem *three = [[UIBarButtonItem alloc]initWithTitle:@"Three" style:UIBarButtonItemStylePlain target:self action:@selector(testMethod)];

    // create a spacer
    UIBarButtonItem *space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
    space.width = 30;

    NSArray *buttons = @[one, space, two, space, three];

    self.navigationItem.rightBarButtonItems = buttons;

}

成功完成此操作会将导航栏更改为蓝色,但标题或按钮都不会显示。无论我尝试什么方法,我似乎无法获得它的头衔。我不知道它是否与tabviewcontroller有关。有什么想法吗?

谢谢,

0 个答案:

没有答案