标签:使用 strong io for ar 代码 div 管理
一、创建UITabBarController
// 创建一个UITabBarController对象UITabBarController *tabBarController = [[UITabBarController alloc] init]; // tabBarController.delegate = self; // 创建一系列要添加到每个具体Tab卡的视图控制器MyViewController *vc1 = [[MyViewController alloc] init]; MyOtherViewController *vc2 = [[MyViewController alloc] init]; // 将创建好的这些视图控制器先添加到一个Array对象中,再将此数组分配给Tab Bar Controller的viewControllers属性NSArray *controllers = [NSArray arrayWithObjects:vc1,vc2,nil]; tabBarControllers.viewControllers = controllers; /* 也或者 NSMutableArray *controllers =[[NSMutableArray alloc] initWithCapacity:2]; [controllers addObject:vc1]; [controllers addObject:vc2]; */ // 将TabBar控制器的当前视图添加到窗口[window addSubview:tabBarController.view]; // 或者设置应用窗口的根视图管理器为TabBarController self.window.rootViewController = self.tabBarController;
- (id)init { if(self = [super initWithNibName:@"MyViewController" bundle:nil]) { self.title = @"My View Controller"; UIImage *anImage = [UIImage imageNamed:@"MyImage.png"]; UITabBarItem *theItem = [[UITabBarItem alloc] initWithTitle:@"Home" image:anImage tag:0]; self.tabBarItem = theItem; [theItem release]; } return self; }
- (id)init { if([super init] != nil) { UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Home" image:[UIImage imageNamed:@"MyImage.png"] tag:0]; self.tabBarItem = item; [item release]; } return self; }
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { // 捕捉selectedIndex,可确定当前所选选项卡 NSNumber *tabNumber = [NSNumber numberWithInt:[tabBarController selectedIndex]]; // 使用iPhone内置用户默认系统NSUserDefaults,利用setObject:forKey:为关键字设定值 [[NSUserDefaults standardUserDefaults] setObject:tabNumber forKey:@"selectedTab"]; [[NSUserDefaults standardUserDefaults] synchronize]; // 选项卡图标项右上角红色小红圈数字提示 viewController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d",80]; }
创建UITabBarController,布布扣,bubuko.com
标签:使用 strong io for ar 代码 div 管理
原文地址:http://www.cnblogs.com/xubojoy/p/3885923.html