iPhone开发 使用tabbarcontroller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
//生成各个视图控制器
MedicalData* aa = [[MedicalData alloc]init];
HealthRecord* bb = [[HealthRecord alloc]init];
KonwledgeBase* cc = [[KonwledgeBase alloc]init];
CarePrescription* dd = [[CarePrescription alloc]init];
//加入一个数组
NSArray* controllerArray = [[NSArray alloc]initWithObjects:aa,bb,cc,dd ,nil];
//创建UITabBarController控制器 (定义在.h中,否在开启arc会自动释放掉,内存访问出错)
tabBarController = [[UITabBarController alloc]init];
//设置委托
tabBarController.delegate = self;
//设置UITabBarController控制器的viewControllers属性为我们之前生成的数组controllerArray
tabBarController.viewControllers = controllerArray;
//默认选择第1个视图选项卡(索引从0开始的)
tabBarController.selectedIndex = 0;
//设置TabBarItem的标题与图片
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:0] setTitle:@"aa"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:0] setImage:[UIImage imageNamed:@"1517.png"]]; //30 * 30
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:1] setTitle:@"bb"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:1] setImage:[UIImage imageNamed:@"light.png"]];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:2] setTitle:@"cc"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:2] setImage:[UIImage imageNamed:@"podcaste.png"]];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:3] setTitle:@"dd"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:3] setImage:[UIImage imageNamed:@"setting.png"]];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:4] setTitle:@"ee"];
[(UITabBarItem *)[tabBarController.tabBar.items objectAtIndex:4] setImage:[UIImage imageNamed:@"unlock.png"]];
//读取
UIViewController* activeController = tabBarController.selectedViewController;
if(activeController == aa){
//
}
//把tabBarController的view作为子视图添加到window
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
摘自 凡娃软件
相关新闻>>
- 发表评论
-
- 最新评论 更多>>