Search code examples
iphonexcode4uitabbarcontroller

Load a tabbarcontroller when back button is clicked in xcode?


When i click on back button then Im loading a particular view.But to that particular view I have to add a tabbarController.How can i do it..?When i try to add it doesnot get added..Couldnot understand y ?

 -(IBAction)switchtofirst {
AppViewController *first=[[AppViewController alloc] initWithNibName:@"AppViewController" bundle:nil];  
        Login *second=[[Login alloc]initWithNibName:@"Login" bundle:nil];
        second.title=@"Login";
        NSArray *viewArray=[[NSArray alloc] initWithObjects: first,second,nil];
        tabBarController=[[UITabBarController alloc] init];
        [tabBarController setViewControllers:viewArray animated:NO];
        AppViewController *gp=[AppViewController alloc];
         [gp.view addSubview:tabBarController.view]; 
      [self presentModalViewController:gp animated:NO];
        [gp release];
         }

Solution

  • Try something like this:

    -(IBAction)switchtofirst {
    
        AppViewController *first = [[AppViewController alloc] initWithNibName:@"AppViewController" bundle:nil];
        Login *second=[[Login alloc]initWithNibName:@"Login" bundle:nil];
        second.title=@"Login";
    
        NSArray *viewArray= [NSArray arrayWithObjects:first, second, nil];
    
        tabBarController=[[UITabBarController alloc] init];
        [tabBarController setViewControllers:viewArray animated:NO];
    
        [self presentViewController:tabBarController animated:YES completion:nil];
    }