編集 2: この問題を修正しました。UINavigationBar のカスタム背景画像を次のように設定していました。
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
[imgView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"NavigationBarBackground" ofType:@"png"]]];
[navBar addSubview:imgView];
[navBar sendSubviewToBack:imgView];
[imgView release];
UINavigationController のビュー コントローラー スタックの最初のビュー コントローラーではこれで問題ありませんでしたが、サブ ビューによってこのコードが再実行され、カスタム背景が前面に配置されていました。
修正: ナビゲーション コントローラーのカスタム背景のコードをすべて削除し、次の方法で UINavigationBar クラスを EXTEND します。
UINavigationBar+CustomImage という新しい .h / .m ファイルを作成します。.h コードを次のように設定します。
@interface UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect;
@end
そして .m へ:
#import "UINavigationBar+CustomImage.h"
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"NavigationBarBackground.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
そして出来上がり!すべてが正常に動作するようになりました。
--- END EDIT 2 ---
次のようにドリルダウンする UINavigationController があります。
HOMEPAGE > DETAIL PAGE > MAP VIEW
DETAIL PAGE は、次のように viewDidLoad 内の rightBarButtonItem にカスタム UIToolbar (3 つのボタンを含む) を追加します。
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 1.0, 157.0, 44.1)];
[imgView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"NavigationBarBackground" ofType:@"png"]]];
[tools addSubview:imgView];
[tools sendSubviewToBack:imgView];
[tools setTintColor:[UIColor colorWithRed:127/255.0 green:184/255.0 blue:72/255.0 alpha:1.0]];
[imgView release];
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithTitle:@"Filter" style:UIBarButtonItemStyleBordered target:self action:NULL];
[buttons addObject:bi];
[bi release];
bi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Map.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(showMap:)];
[buttons addObject:bi];
[bi release];
bi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Favourite.png"] style:UIBarButtonItemStyleBordered target:self action:NULL];
[buttons addObject:bi];
[bi release];
[tools setItems:buttons animated:NO];
[buttons release];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
これは、DETAIL VIEW ページを表示すると完全に表示され、MAP VIEW に移動すると、カスタム UIToolbar が (予想どおり) 消えますが、DETAIL VIEW に戻ると、カスタム UIToolbar が表示されなくなります。ただし、「マップ」ボタンがあるはずのエリアをタップできるため、そこにあり、MAP VIEW に戻ります。
DETAIL ビューに戻ったときに、この UIToolbar を再び表示する方法を教えてください。
上記とまったく同じ効果を持つviewWillAppearでカスタムUIToolbarを再構築しようとしました。
編集- これは、viewDidAppear メソッド内にカスタム UIToolbar を構築するコードを配置すると機能します。ただし、ビューがスライドして戻ると、カスタム rightBarButtonItem が表示されるため、このソリューションは好きではありません。これは、ページが表示される前にナビゲーションコントローラーが初期化されていないことに関係していますか?