UINavigationController サンプル
コーディング時に大枠を何処かからコピーペーストして修正実装
するパターンがよくあると思います。
実装時、コピペ用のテンプレートとしてご利用ください。
コードサンプル
■ window にセットする時
TestViewController *testViewController = [[TestViewController alloc] init];
UINavigationController *testNavigationController = [[UINavigationController alloc] initWithRootViewController:testViewController];
testNavigationController.navigationBarHidden = YES;
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
[self.window addSubview:testNavigationController.view];
}
else
{
// use this method on ios6
self.window.rootViewController = testNavigationController;
}
■ 画面遷移時
TestViewController *viewController = [[TestViewController alloc] init];
// 通常表示
[self.navigationController pushViewController:viewController animated:YES];
// モーダル表示
[self.navigationController presentModalViewController:tutorialViewController animated:YES];
// 一つ前に戻る場合(閉じたい View で実行)
[self.navigationController popViewControllerAnimated:YES];
// 一番先頭へ戻る場合(閉じたい View で実行)
[self.navigationController popToRootViewControllerAnimated:YES];
// 位置を指定して戻る場合 2つ戻る場合は -3 を指定(閉じたい View で実行)
int viewCount = self.navigationController.viewControllers.count - 4;
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:viewCount] animated:YES];
■ タイトルのカスタマイズ
UILabel *naviTitlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
naviTitlelabel.text = @"Title\nTitle";
self.navigationItem.titleView = naviTitlelabel;