ナビゲーションバーにカスタムアイテムを追加するために、異なるタイプのコードで数時間戦っています。残念なことにその失敗し、theresデバッグエラーはありません。今はバーのタイトルだけを変更することができます。カスタムアイテムをナビゲーションバーに追加する方法
コードは、特定のViewControllerでviewDidLoadメソッドに追加されます。
UIBarButtonItem *gotoNext = [[UIBarButtonItem alloc] initWithTitle:@"Goto next" style:UIBarButtonItemStylePlain target:self action:@selector(gotoNextAction)];
self.navigationItem.rightBarButtonItem = gotoNext;
私は残念ながら運なしで次のコードを試してみました:
UIView* container = [[UIView alloc] init];
UIButton * button = [[UIButton alloc] init];
[button setTitle:@"Test" forState:UIControlStateNormal];
[container addSubview:button];
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:container];
self.navigationItem.rightBarButtonItem = item;
どこコンテナのフレームが設定されていますか?背景色? – Mangesh