Windowbase应用程序中的自定义TabbarController

时间:2012-07-06 11:13:29

标签: iphone ipad

嗨朋友我想为windows base开发一个应用程序第一页加载页面然后在下一个视图之后我想添加UitabbarController。我实现了这段代码。

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


    flag=1;


    splash *objSplash=[[splash alloc]initWithNibName:@"splash" bundle:nil];

    Home *placeholder1 = [[Home alloc] initWithNibName:@"Home" bundle:nil];
    placeholder1.title=@"Home";
    placeholder1.tabBarItem.image=[UIImage imageNamed:@"home1.png"];

    shopHome *placeholder2 = [[shopHome alloc] initWithNibName:@"shopHome" bundle:nil];
    placeholder2.title=@"Store";
    placeholder2.tabBarItem.image=[UIImage imageNamed:@"Shop.png"];

    Search1 *placeholder3 = [[Search1 alloc] initWithNibName:@"Search1" bundle:nil];
    placeholder3.title=@"Search";
    placeholder3.tabBarItem.image=[UIImage imageNamed:@"search2.png"];

    info *placeholder4 = [[info alloc]initWithNibName:@"info" bundle:nil];
    placeholder4.title=@"Info";
    placeholder4.tabBarItem.image=[UIImage imageNamed:@"info1.png"];

    CartView *placeholder5=[[CartView alloc]initWithNibName:@"CartView" bundle:nil];
    placeholder5.title=@"Cart";
    placeholder5.tabBarItem.image=[UIImage imageNamed:@"Cart.png"];

    NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] init];

    UINavigationController *localNavController;


    localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder1];
    localNavController.navigationBar.tintColor=[UIColor blackColor];

    // Add navigation controller to the local vc array (1 of 2)
    [localViewControllersArray addObject:localNavController];
    [localNavController release];

    localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder2];
    [localViewControllersArray addObject:localNavController];
    [localNavController release];

    localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder3];
    [localViewControllersArray addObject:localNavController];
    [localNavController release];

    if(flag==1)
    {
        localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder5];
        [localViewControllersArray addObject:localNavController];
        [localNavController release];


    }

    localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder4];
    [localViewControllersArray addObject:localNavController];
    [localNavController release];

    tabBarController = [[UITabBarController alloc] init]; 
    //tabBarController.viewControllers = [NSArray arrayWithObjects:placeholder1, placeholder2, placeholder3, placeholder4, nil]; 
    tabBarController.viewControllers = localViewControllersArray;
    //tabBarController.tintColor=[UIColor colorWithRed:160/256.0 green:82/256.0 blue:45/256.0 alpha:1.0];
    //tabBarController.tabBar.backgroundColor=[UIColor colorWithRed:160/256.0 green:82/256.0 blue:45/256.0 alpha:1.0];



    tabBarController.delegate=self;

    [placeholder1 release];
    [placeholder2 release];
    [placeholder3 release];
    [placeholder4 release];

    [self.window addSubview:objSplash.view];

    //[self.window addSubview:navigationController.view];


    //[self.window addSubview:tabBarController.view];

    [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(goToNext) userInfo:nil repeats:NO];


    flag=1;

    [self parsingData];

    [window makeKeyAndVisible];

    return YES;
}


-(void)goToNext
{
    //[self.navigationController.view addSubview:tabBarController.view];


    [self.window addSubview:tabBarController.view];
}

1 个答案:

答案 0 :(得分:0)

只需尝试实现这一个:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   
    splash *objSplash=[[splash alloc]initWithNibName:@"splash" bundle:nil];
    Home *placeholder1 = [[Home alloc] initWithNibName:@"Home" bundle:nil];
    placeholder1.title=@"Home";
    placeholder1.tabBarItem.image=[UIImage imageNamed:@"home1.png"];

    shopHome *placeholder2 = [[shopHome alloc] initWithNibName:@"shopHome" bundle:nil];
    placeholder2.title=@"Store";
    placeholder2.tabBarItem.image=[UIImage imageNamed:@"Shop.png"];

    Search1 *placeholder3 = [[Search1 alloc] initWithNibName:@"Search1" bundle:nil];
    placeholder3.title=@"Search";
    placeholder3.tabBarItem.image=[UIImage imageNamed:@"search2.png"];

    info *placeholder4 = [[info alloc]initWithNibName:@"info" bundle:nil];
    placeholder4.title=@"Info";
    placeholder4.tabBarItem.image=[UIImage imageNamed:@"info1.png"];

    CartView *placeholder5=[[CartView alloc]initWithNibName:@"CartView" bundle:nil];
    placeholder5.title=@"Cart";
    placeholder5.tabBarItem.image=[UIImage imageNamed:@"Cart.png"];

    NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] init];
    UINavigationController *localNavController;
    localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder1];
    localNavController.navigationBar.tintColor=[UIColor blackColor];

    // Add navigation controller to the local vc array (1 of 2)
    [localViewControllersArray addObject:localNavController];
    [localNavController release];
    localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder2];
    [localViewControllersArray addObject:localNavController];
    [localNavController release];

    localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder3];
    [localViewControllersArray addObject:localNavController];
    [localNavController release];

    if(flag==1)
    {
        localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder5];
        [localViewControllersArray addObject:localNavController];
        [localNavController release];
    }
    localNavController = [[UINavigationController alloc] initWithRootViewController:placeholder4];
    [localViewControllersArray addObject:localNavController];
    [localNavController release];

    tabBarController = [[UITabBarController alloc] init]; 
    tabBarController.viewControllers = localViewControllersArray;
    tabBarController.delegate=self;
    [placeholder1 release];
    [placeholder2 release];
    [placeholder3 release];
    [placeholder4 release];

    [self.window addSubview:objSplash.view];
    [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(goToNext) userInfo:nil repeats:NO];
    [window makeKeyAndVisible];
    return YES;
}

-(void)goToNext
{
    [self.window addSubview:tabBarController.view];
}

@implementation Home
- (id)initWithTitle:(NSString*)theTitle {
    if (self = [super init]) {
        self.tabBarItem.image = [UIImage imageNamed:@"Home.png"];
        self.title = theTitle;
    }
    return self;
}

注意: 这已经过测试解决方案希望它也适合你。