
####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]; FirstViewController *firstViewController = [[FirstViewController alloc]initWithNibName:nil bundle:NULL]; UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:nil bundle:NULL]; UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; UITabBarController *tabBarController = [[UITabBarController alloc] init]; [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) { self.title = @"First"; self.tabBarItem.image = [UIImage imageNamed:@"FirstTab"]; } return self; } - (void)viewDidLoad{ [super viewDidLoad]; 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) { self.title = @"Second"; self.tabBarItem.image = [UIImage imageNamed:@"SecondTab"]; } return self; }
- (void)viewDidLoad{ [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; }
|
Reference
近期评论