|
【共通】
【NSObject】 【UIResponder】 【UIViewController】 【UIView】 【UIControl】 【UIScrollView】 |
|
【CoreLocation】
【MapKit】 |
HOME > UINavigationController
UINavigationController
UINavigationControllerクラスは、階層的な画面遷移を管理するクラスです。
下右図のようにUINavigationControllerの下にルート画面があり、その下にサブ画面がぶら下がっているイメージです。
UINavigationControllerのクラス階層
NSObject
↑
UIResponder
↑
UIViewController
↑
UINavigationController
生成
// 生成
UINavigationController *nav =
[[UINavigationController alloc] initWithRootViewController:ルート画面];
// 自身を管理しているUINavigationControllerを取得
self.navigationController;
※階層的な画面遷移の一番元となるルート画面(UIViewControllerのサブクラス)の指定は必須です。
UINavigationControllerのプロパティ
| プロパティ名/型 | 読専 | 説明 |
|---|---|---|
| delegate (UINavigationControllerDelegate) |
デリゲートを指定する (例)nav.delegate = self; |
|
| visibleViewController (UIViewController) |
||
| viewControllers (NSArray) |
管理している全画面 | |
| navigationBar (UINavigationBar) |
ナビゲーションバー | |
| navigationBarHidden (BOOL) |
ナビゲーションバーの表示・非表示の指定 (例)nav.navigationBarHidden = YES; |
|
| topViewController (UIViewController) |
現在表示中の画面 | |
| toolbar (UIToolbar) |
○ | |
| toolbarHidden (BOOL) |
主要なプロパティのみ掲載しています。
上記「UINavigationControllerのクラス階層」にあるクラスのプロパティも使用できます。
UINavigationControllerのメソッド
| メソッド名 | 説明 |
|---|---|
| -(void)pushViewController: (UIViewController *)viewController animated:(BOOL)animated |
画面を追加して、追加した画面を表示する ※下記例文1参照 |
| -(UIViewController *)popViewControllerAnimated: (BOOL)animated |
1つ上の画面に戻る ※下記例文2参照 |
| -(void)setNavigationBarHidden: (BOOL)hidden animated:(BOOL)animated |
ナビゲーションバーの表示・非表示設定 ※下記例文3参照 |
| -(void)setToolBarHidden: (BOOL)hidden animated:(BOOL)animated |
ツールバーの表示・非表示設定 ※下記例文4参照 |
主要なメソッドのみ掲載しています。
上記「UINavigationControllerのクラス階層」にあるクラスのメソッドも使用できます。
//(例文1)次画面(nextView)へアニメーションをしつつ遷移する
[self.navigationController pushViewController:nextView animated:YES];
//(例文2)階層を1つ戻る
[self.navigationController popViewControllerAnimated:YES];
//(例文3)ナビゲーションバーの表示・非表示
[self.navigationController setNavigationBarHidden:NO animated:YES];
[self.navigationController setNavigationBarHidden:YES animated:YES];
//(例文4)ツールバーの表示・非表示
[self.navigationController setToolbarHidden:NO animated:YES];
[self.navigationController setToolbarHidden:YES animated:YES];
UINavigationController例文
//ナビゲーションコントローラ例文
UIView *view1 = [[UIView alloc] init];
UINavigationController *nac =
[[UINavigationController alloc] initWithRootViewController:view1];
[window addSubView:nac.view];
[window makeKeyAndVisible];
//ナビゲーションコントローラを青色にする
self.navigationController.navigationBar.tintColor = [UIColor blueColor];