iPhone开发 使用tabbarcontroller

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 20:14 点击:

- (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;

}

 摘自 凡娃软件

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Lexical or Preprocessor Issue 'xxx.h
    • ios学习笔记(二)xcode 4.3.2下实现基本交互
    • ios版本的helloworld
    • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
    • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
    • IOS类似iphone通讯录TableView的完整demo【附源码】
    • UITableView一些方法
    • [iPhone中级]iPhone团购信息客户端的开发 (二)
    • 如何为Iphone应用创建启动界面
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1