UINavigationController子类navigationItem忽略-setLeftBarButtonItem

时间:2013-04-22 21:52:08

标签: iphone uinavigationcontroller uitabbarcontroller uinavigationitem

我目前有一个UINavigationController的子类,它具有以下viewDidLoad函数。

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"HI" 
                                                                   style:UIBarButtonItemStylePlain
                                                                  target:self
                                                                  action:@selector(manage)];
    [self.navigationItem setLeftBarButtonItem:leftButton];

    [self.navigationBar setBackgroundImage:[[UIImage imageNamed:@"top_nav_bg.png"] stretchableImageWithLeftCapWidth:3.0 topCapHeight:0.0] forBarMetrics:UIBarMetricsDefault];

}

UINavigationController子类是UITabBarBarController子类中的一个选项卡,带有以下viewDidLoad。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Change some of the look of the main tab bar
    [self.tabBar setBackgroundImage:[[UIImage imageNamed:@"tab_nav_bg.png"] stretchableImageWithLeftCapWidth:2.0 topCapHeight:0.0]];
    [self.tabBar setSelectionIndicatorImage:[[UIImage imageNamed:@"tab_nav_bg_active.png"] stretchableImageWithLeftCapWidth:2.0 topCapHeight:0.0]];

    // Load the various view controllers for this view
    SBHomeViewController *homeViewController = [[SBHomeViewController alloc] init];
    [homeViewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_home_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_home.png"]];
    [homeViewController.tabBarItem setImageInsets:UIEdgeInsetsMake(5.0, 0.0, -5.0, 0.0)];

    // The navigation controller that will hold the home view
    SBMainNavigationViewController *homeNavController = [[SBMainNavigationViewController alloc] initWithRootViewController:homeViewController];

    self.viewControllers = @[homeNavController];
}

一切似乎都很好。正在加载来自UINavigationController viewDidLoad的正确导航栏背景图像。但是,leftBarButtontem根本没有设置。为了它的价值,我尝试将它设为rightBarButtonItem,但这也不起作用。

思想?

1 个答案:

答案 0 :(得分:6)

导航控制器是其他视图的容器和导航栏的主机。但是,它永远不是导航堆栈的一部分。仅查看作为堆栈一部分的控制器会对条形按钮项产生影响。

不是将条形按钮项设置到导航控制器导航项上,而是将其设置到根视图控制器导航项上。