ios7 uitabbarcontroller

####iOS7 Programming Cookbook 第一章学习笔记 UITabBarController

#####Presenting Multiple View Controllers with UITabBarController

#####AppDelegate.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{


self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

[self.window makeKeyAndVisible];

//创建 firstVC
FirstViewController *firstViewController = [[FirstViewController alloc]initWithNibName:nil bundle:NULL];
//创建first的nav,设置rootview为firstViewController
UINavigationController *firstNavigationController =
[[UINavigationController alloc]
initWithRootViewController:firstViewController];

//创建secondVC
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:nil bundle:NULL];
//创建second的nav,设置rootView为secondViewController
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
//创建Tab
UITabBarController *tabBarController = [[UITabBarController alloc] init];
//添加2个view到 tab
[tabBarController setViewControllers:
@[firstNavigationController, secondNavigationController]];

self.window.rootViewController = tabBarController;

return YES;

}

#####FirstViewController.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil{

self = [super initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if (self != nil) {
//nav title和bar title为First
self.title = @"First";
//设置tabbar图片
self.tabBarItem.image = [UIImage imageNamed:@"FirstTab"];
}
return self;

}
- (void)viewDidLoad{
[super viewDidLoad];
//设置view背景色为白色
self.view.backgroundColor = [UIColor whiteColor];
}

#####SecondViewController.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil{

self = [super initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if (self != nil) {
//nav title和bar title为Second
self.title = @"Second";
//设置tabbar图片
self.tabBarItem.image = [UIImage imageNamed:@"SecondTab"];
}
return self;

}

- (void)viewDidLoad{
[super viewDidLoad];
//设置view背景色为白色
self.view.backgroundColor = [UIColor whiteColor];
}

Reference