私は、ナビゲーション コントローラーを備えたアプリケーションでトレーニングを行っており、ユーザーは 2 つのビュー コントローラーを切り替えることができます。
ルート ビュー コントローラー クラスは ViewController と呼ばれ、アプリ デリゲートにナビゲーション コントローラーをプログラムで追加する方法は次のとおりです。
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
navController= [[UINavigationController alloc]initWithRootViewController: viewController];
self.window.rootViewController= navController;
これは navController です:
@property (strong, nonatomic) UINavigationController* navController;
2 番目のビュー コントローラーは SecondViewController と呼ばれます。ユーザーがバー ボタン項目をクリックするたびにプッシュします。
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle: @"Second View" style: UIBarButtonItemStylePlain target: self action: @selector(switchView:)];
これは実行されたセレクターです:
- (void) switchView : (id) sender
{
if(!nextController)
{
nextController= [[SecondViewController alloc]initWithNibName: @"SecondViewController" bundle: nil];
}
[self.navigationController pushViewController: nextController animated: YES];
}
次に、2番目のView Controllerに、最初のビューに切り替わる「戻る」というタイトルのボタンが自動的に表示されます.それは私にとっては問題ありませんが、タイトルとスタイルを設定したいので、タイトルを変更しようとしています. :
self.navigationItem.backBarButtonItem.title= @"First View";
しかし、何もする必要はありません。タイトルはまだ「戻る」です。どうすれば変更できますか?
また、私は間違った、または非効率的なアプローチに従っていませんか?