Search code examples
iphoneuitabbarcontrolleruitabbar

Can i take tabbar controller in view controller rather than delegate class?


I am using a UINavigation Controller in a delegate class. After navigating the two views class on the third view class I need a tabbar controller which can control three another ViewControllers and the tabbar should not be seen on first two view controllers. How can i do this ?

- (void)viewDidLoad
{

    [super viewDidLoad];

    self.title =@"Scan";

    tabController =[[UITabBarController alloc]init];

    ScanTicketView *scan =[[ScanTicketView alloc]initWithNibName:@"ScanTicketView" bundle:nil];

    SearchView *search =[[SearchView alloc]initWithNibName:@"SearchView" bundle:nil];

    HistoryView *history =[[HistoryView alloc]initWithNibName:@"HistoryView" bundle:nil];

   tabController.viewControllers=[NSArray arrayWithObjects:scan,search,history, nil];

    [self presentModalViewController:tabController animated:YES];

}

Solution

  • Yes you can. See this link to an example

    In your second view controller where you want to push to you third view(tab controller) do this

    UITabBarController *tabBarController=[[UITabBarController alloc]init];
    tabBarController.viewControllers=[NSArray arrayWithObjects:firstViewController,secondViewController,thirdViewController, nil];
    //[self.navigationController pushViewController:tabBarController animated:YES];// this works too but since it seems to be against Apple's Human interface Guidelines you can present the view instead of pushing
    [self presentModalViewController:tabBarController animated:NO];