Skip to content

2.2 UITabController

tamotamago edited this page Apr 18, 2013 · 11 revisions

UITabBarController Class Reference | iOS View Controllerプログラミングガイド

概要

tabController1

UITabBarController は TabBar インタフェースを用いて ViewController を管理するコンテナです。

tabController2

Source:View Controller Programming Guide for iOS

UITabBarController における重要な property と method は以下の通りです。

  • viewControllers - viewController が含まれている NSArray
  • selectedViewController - 現在表示されている ViewController を取得、別のViewControllerに変更可能なプロパティ
  • delegate - 表示変更などのイベントを取得できる delegate UITabBarControllerDelegate Protocol

tab の表示は ViewController の UITabBarItem を設定することで変更可能

実装

プロジェクト作成

createTabProject

moreViewControllers と tabBarItem

viewControllers に 5 つ以上の ViewController を管理させる場合、Tab では 4 つを管理し、それ以外の ViewController は more として管理されます。

tabBarItem

MixiFirstViewController.h

#import <UIKit/UIKit.h>

@interface MixiFirstViewController : UIViewController

-(id)initWithImageName:(NSString *)imageNmae;

@end

MixiFirstViewController.m

-(id)initWithImageName:(NSString *)imageName;
{
    self = [super initWithNibName:@"MixiFirstViewController" bundle:nil];
    if (self) {
        self.title = imageName;
        self.tabBarItem.image = [UIImage imageNamed:imageName];
    }
    return self;
}

MixiAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *vc1 = [[MixiFirstViewController alloc] initWithImageName:@"first"];
    UIViewController *vc2 = [[MixiSecondViewController alloc] initWithNibName:@"MixiSecondViewController" bundle:nil];
    UIViewController *vc3 = [[MixiFirstViewController alloc] initWithImageName:@"third"];
    UIViewController *vc4 = [[MixiFirstViewController alloc] initWithImageName:@"fourth"];
    UIViewController *vc5 = [[MixiFirstViewController alloc] initWithImageName:@"fifth"];
    UIViewController *vc6 = [[MixiFirstViewController alloc] initWithImageName:@"sixth"];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = @[vc1, vc2, vc3, vc4, vc5, vc6];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

画像ファイルはこちら

tab のバッジ

tabBadge

tabBar の上にバッジを表示することが可能です。

self.tabBarItem.badgeValue = @"5";

問題

tabBarControlelr の中の一つに NavigationController を管理させてください。

  1. 導入
  2. Objective C の基礎
  3. メモリ管理
  4. UIViewController1 - UIViewController のカスタマイズ
  5. UIViewController2 - ModalViewController
  6. UIViewController3 - ライフサイクル
  7. UIKit 1 - container, rotate-
  8. UINavigationController
  9. UITabController
  10. Custom Container View Controller
  11. Supporting Multiple Interface Orientations
  12. UIKit 2- UIView -
  13. UIView
  14. UIView のカスタマイズ
  15. UIView Animation
  16. UIKit 3 - table view -
  17. UITableView について
  18. UITableViewとNavigationController
  19. custom UITableViewCell の作成
  20. 4.4 UITableViewのその他のオプション、カスタマイズ
  21. UIKit 4 - images -
  22. UIImage (CoreGraphics)
  23. UIImageView
  24. Accets Library
  25. CoreImage
  26. UIKit 4 - text -
  27. UILabel
  28. UITextView
  29. KeybordNotification
  30. 非同期処理系
  31. NSURLConnection (json シリアライザ)
  32. Blocks
  33. GCD
  34. ローカルキャッシュ
  35. UserDefaults
  36. FileManager
  37. CoreData
  38. SQLite
  39. Instruments
  40. leak
  41. time profiler
  42. その他
  43. 単体テスト (GHUnit)
  44. 結合テスト (KIF)
  45. cocoaPods でライブラリ管理

edit sidebar

Clone this wiki locally