UITabBarController

来源:互联网 发布:mac版淘宝客户端 编辑:程序博客网 时间:2024/05/16 11:24

修改AppDelegate.m中的代码


#import "AppDelegate.h"

#import "FirstViewController.h"

#import "SecondViewController.h"


@implementation AppDelegate


- (void)dealloc

{

    [_window release];

    [super dealloc];

}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]]autorelease];

     self.window.backgroundColor = [UIColorwhiteColor];

    

    //实例化对象

    FirstViewController *first = [[FirstViewControlleralloc]init];

    SecondViewController *second = [[SecondViewControlleralloc]init];

    

    //创建UINavigationController

    UINavigationController *nav1 = [[UINavigationControlleralloc]initWithRootViewController:first];

    [first release];

    

    UINavigationController *nav2 = [[UINavigationControlleralloc]initWithRootViewController:second];

    [second release];

    

    NSArray *arr = [NSArrayarrayWithObjects:nav1,nav2,nil];

    

    //实例化标签控制器,并设置viewController属性为上面的数组

    UITabBarController *tabBar = [[UITabBarControlleralloc]init];

    

    tabBar.viewControllers =arr;

    

    //配置tabBar

    [nav1.tabBarItem setTitle:@"First"];

    [nav2.tabBarItem setTitle:@"Second"];

    

   //标签栏控制器作为根控制器

    self.window.rootViewController = tabBar;

    

    //更改首次选中标签

    tabBar.selectedIndex = 0;

    

    //更改标签上的角标

    [nav1.tabBarItem setBadgeValue:@"1"];

    [nav2.tabBarItem setBadgeValue:@"2"];

    

    [tabBar release];

    

    [self.windowmakeKeyAndVisible];

    

    return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application

{


}


- (void)applicationDidEnterBackground:(UIApplication *)application

{


}


- (void)applicationWillEnterForeground:(UIApplication *)application

{


}


- (void)applicationDidBecomeActive:(UIApplication *)application

{


}


- (void)applicationWillTerminate:(UIApplication *)application

{


}


@end


原创粉丝点击