-
Notifications
You must be signed in to change notification settings - Fork 0
2.1 UINavigationController
UINavigationController Class Reference | View Controller Programming Guide for iOS
Source:View Controller Programming Guide for iOS
UINavigationController は UIViewController を階層的に管理するコンテナです。複数の UIViewController はスタックで管理されます。またその各 UIViewController にナビゲートするインタフェース(UINavigationBar, UIToolBar)も管理します。
Source:View Controller Programming Guide for iOS
UINavigationController における重要な property と method は以下の通りです。
- topViewController - スタックのトップにいる viewController
- viewControllers - viewController が含まれている NSArray
- pushViewController:animated: - viewControllers スタックに push され画面遷移します
- popViewController:Animated: - スタックから pop され画面遷移します
- delegate methods を実装することで画面遷移の通知を受け取れます
無限に push する画面遷移を実装しましょう。
MixiAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[MixiViewController alloc] initWithNibName:@"MixiViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
MixiViewController.h
#import <UIKit/UIKit.h>
@interface MixiViewController : UIViewController
- (IBAction)pressPushButton:(id)sender;
@end
MixiViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.title = [NSString stringWithFormat:@"%d", [self.navigationController.viewControllers count]];
}
- (IBAction)pressPushButton:(id)sender
{
[self.navigationController pushViewController:[[MixiViewController alloc] init] animated:YES];
}
MixiViewController.xib
rootView の TopBar を NavigationBar にすると、NavigationBar が現れます。これは実際に NavigationBar を設置しているのでは無く、NavigationBar がある体でレイアウトをするという意味です。この ViewController には NavigationBar が入ってくるので、それを考慮して他のレイアウトを作ることが出来ます。
確認 : navigationController.viewControllers にスタックされていることを、ログで確認してください。
###問題 アプリ起動時で 5 階層目にいるように実装してください。 (HINT:setViewControllers:)
UINavigationBar Class Reference
UINavigationItem Class Reference
UINavigationBar は UINavigationItem を管理するためのコンテナです。UINabigationItem は各 ViewController が持っていて、NavigationBar に表示させる情報を管理しています。
Source :
iOS View Controllerプロ グラミングガイド
NavigationBar 右上方にボタンを設置してみましょう。ボタンタップで pop を実装しましょう。
MixiVIewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.title = [NSString stringWithFormat:@"%d", [self.navigationController.viewControllers count]];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"pop" style:UIBarButtonItemStylePlain target:self action:@selector(pressPopButton)];
self.navigationItem.rightBarButtonItem = rightButton;
}
- (void)pressPushPopButton
{
[self.navigationController popViewControllerAnimated:YES];
}
UIAppearance Protocol Reference
UIAppearance を用いると、特定の UIComponent のデザインを一括して変更することが出来ます。
MixiAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self customizeAppearance];
.
.
.
}
- (void)customizeAppearance
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"customNavBarImage1"] forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTintColor:[UIColor blackColor]];
}
画像データはこちら customNavBarImage1.png
詳しい実践は以下をご参照ください : iOS 5 ユーザーインターフェースのカスタマイズ
- 導入
- Objective C の基礎
- メモリ管理
- UIViewController1 - UIViewController のカスタマイズ
- UIViewController2 - ModalViewController
- UIViewController3 - ライフサイクル
- UIKit 1 - container, rotate-
- UINavigationController
- UITabController
- Custom Container View Controller
- Supporting Multiple Interface Orientations
- UIKit 2- UIView -
- UIView
- UIView のカスタマイズ
- UIView Animation
- UIKit 3 - table view -
- UITableView について
- UITableViewとNavigationController
- custom UITableViewCell の作成
- 4.4 UITableViewのその他のオプション、カスタマイズ
- UIKit 4 - images -
- UIImage (CoreGraphics)
- UIImageView
- Accets Library
- CoreImage
- UIKit 4 - text -
- UILabel
- UITextView
- KeybordNotification
- 非同期処理系
- NSURLConnection (json シリアライザ)
- Blocks
- GCD
- ローカルキャッシュ
- UserDefaults
- FileManager
- CoreData
- SQLite
- Instruments
- leak
- time profiler
- その他
- 単体テスト (GHUnit)
- 結合テスト (KIF)
- cocoaPods でライブラリ管理