-
Notifications
You must be signed in to change notification settings - Fork 337
2.1 UINavigationController
UINavigationController Class Reference | View Controller Programming Guide for iOS
UINavigationController は UIViewController を階層的に管理するコンテナです。複数の UIViewController はスタックで管理されます。またその各 UIViewController にナビゲートするインタフェース(UINavigationBar, UIToolBar)も管理します。
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 に表示させる情報を管理しています。
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:nil];
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]];
}
詳しい実践は以下をご参照ください : iOS 5 ユーザーインターフェースのカスタマイズ
はじめに
-
導入
-
1.3 UIViewController1 UIViewController のカスタマイズ(xib, autoresizing)
-
UIKit 1 - container, rotate-
-
UIKit 2- UIView -
-
UIKit 3 - table view -
-
UIKit 4 - image and text -
-
ネットワーク処理
-
ローカルキャッシュと通知
-
Blocks, GCD
-
設計とデザインパターン
-
開発ツール
-
テスト
-
In-App Purchase
-
付録