iPhone Programmatically
iPhone Programmatically

Reputation: 1227

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];

}

Upvotes: 0

Views: 280

Answers (3)

Neo
Neo

Reputation: 2807

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];

Upvotes: 0

AppleDelegate
AppleDelegate

Reputation: 4249

Ideally TabBarcontroller should be the starting case of an app..but in rare cases where you want to present it in a viewcontroller follow ..

 UITabBarController *tabBarController=[[UITabBarController alloc]init];
    tabBarController.viewControllers=[NSArray arrayWithObjects:firstViewController,secondViewController,thirdViewController, nil];

    [self presentModalViewController:tabBarController animated:NO];

Upvotes: 0

Rajneesh071
Rajneesh071

Reputation: 31073

Follow my answer ... you can add and remove tabBar whenEver you want
link

Upvotes: 1

Related Questions