views:

1568

answers:

4

Hello I want to create a tabbar application in iPhone using X-code.I have one splash screen and then after that I have my Home Screen where I want to create tabbar in that view. so, I create a tabbar in my ViewDidLoad method.

- (void)viewDidLoad {
    NSLog(@"in Home");
    tabBarController = [[UITabBarController alloc] init];        
    homeViewController = [[HomeViewController alloc]init];  
    NextViewController = [[NextViewController alloc]init];   

    tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController,nextViewController,nil];  
     window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
     [window addSubview:tabBarController.view];                                             
     [window makeKeyAndVisible]; 

    [super viewDidLoad];
}

Now when I compile & Run, It will call the HomeView again & again and when I tap on 2nd tab it will not call the NextView.

So, what is wrong in this code Plz help me..

+1  A: 

Aren't you adding the homeViewController again and again since viewDidLoad is in homeViewController...

CiNN
But if I dont add it then It will not display me the tabbar properly
i think that you need to make a rootcontroller
CiNN
ok thanx but can you give me the code for that, how tabbar is included in that
+1  A: 

Can I recommend that you start a new project from the Tab Bar Application template just to look at how it's done when it's done right? You might even keep that and retrofit your splash screen into it.

dlamblin
A: 

Instead of adding in view did load implement it in application did finish launching.

When tab bar isn't required, just hide in viewdidload

see example code.

-(void)applicationDidFinishLaunching:(UIApplication *)application 
{   
tabBarController=[[UITabBarController alloc] init];
tabBarController.delegate=self;

viewHome=[[DashBoard_Home alloc] initWithNibName:@"DashBoard_Home" bundle:nil];
viewSearch=[[Main_SearchView alloc] initWithNibName:@"Main_SearchView" bundle:nil];
viewMore=[[More_View alloc] initWithNibName:@"More_View" bundle:nil];

UINavigationController *nv1=[[[UINavigationController alloc] initWithRootViewController:viewHome] autorelease];
UINavigationController *nv2=[[[UINavigationController alloc] initWithRootViewController:viewSearch] autorelease];
UINavigationController *nv3=[[[UINavigationController alloc] initWithRootViewController:viewMore] autorelease];
UINavigationController *nv4=[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];
UINavigationController *nv0=[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];
tabBarController.viewControllers=[NSArray arrayWithObjects:nv0,nv1,nv2,nv3,nv4,nil];
nv0.tabBarItem.enabled=NO;nv4.tabBarItem.enabled=NO;

[window addSubview: tabBarController.view];
[window insertSubView: dashBoard.view oversubview:tabbarController.View];
[window makeKeyAndVisible];
}
sugar
A: 

hello

I want to create a splashscreen which after that a tabbarController appears.This tabBarController has 4 items.3 navigationsController and the last one is a TableView. i didn´t know how to load the splash screen i have done at the first time like that:

(void)applicationDidFinishLaunching:(UIApplication *)application {

tabBarController = [[UITabBarController alloc] init];
// creer le tabcontroller pour les news

 newsViewController = [[NewsViewController alloc] init];  
UINavigationController *table1NavController = [[[UINavigationController alloc] initWithRootViewController:newsViewController] autorelease];
[newsViewController release];
[table1NavController setNavigationBarHidden:TRUE];

// creer le viewcontroller pour les parametres 

parametresViewController = [[ParametresViewController alloc] init];
UINavigationController *table2NavController = [[[UINavigationController alloc] initWithRootViewController:parametresViewController] autorelease];
table2NavController.title = @"Mes Parametres";
[parametresViewController release];
[table2NavController setNavigationBarHidden:TRUE];

// creer le viewcontroller pour les reclamations

reclamationsViewController = [[ReclamationsViewController alloc] init];
UINavigationController *table3NavController = [[[UINavigationController alloc] initWithRootViewController:reclamationsViewController] autorelease];
table3NavController.title = @"Mes Reclamations";
[reclamationsViewController release];
[table3NavController setNavigationBarHidden:TRUE];

// creer le viewcontroller pour les factures

facturesViewController = [[FacturesViewController alloc] init];
UINavigationController *table4NavController = [[[UINavigationController alloc]

initWithRootViewController:facturesViewController] autorelease]; table4NavController.title = @"Mes Factures"; [facturesViewController release]; [table4NavController setNavigationBarHidden:TRUE];

tabBarController.viewControllers = [NSArray arrayWithObjects:table1NavController,    table2NavController, table3NavController, table4NavController, nil];

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