UINavigationController子类navigationItem忽略-setLeftBarButtonItem

jos*_*lat 2 iphone uitabbarcontroller uinavigationcontroller 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];

}
Run Code Online (Sandbox Code Playgroud)

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];
}
Run Code Online (Sandbox Code Playgroud)

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

思考?

Wai*_*ain 6

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

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