2

現在、次の viewDidLoad 関数を持つ UINavigationController のサブクラスがあります。

- (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 サブクラスは、次の viewDidLoad を持つ UITabBarBarController サブクラスのタブの 1 つです。

- (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にしようとしましたが、それもうまくいきませんでした.

考え?

4

1 に答える 1

6

ナビゲーション コントローラーは、他のビューのコンテナーであり、ナビゲーション バーのホストです。ただし、ナビゲーション スタックの一部ではありません。スタックの一部であるビュー コントローラーのみが、バー ボタンの項目に影響を与えます。

バー ボタン アイテムをナビゲーション コントローラーのナビゲーション アイテムに設定する代わりに、ルート ビュー コントローラーのナビゲーション アイテムに設定します。

于 2013-04-22T22:14:07.573 に答える