I have a button in a view, I want to add tab bar controller after click the button. How can I do this?
How can I push tab bar controller after click a button from a view in Objective-C?
3.8k Views Asked by Hacer sengul Akac At
3
There are 3 best solutions below
0
On
-(IBAction)BtnPressed:(id)sender
{
UIViewController *searchViewController = [[[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil] autorelease];
searchViewController.title = @"Search";
UIViewController *exploreViewController = [[[SearchViewController alloc] initWithNibName:@"ExploreViewController" bundle:nil] autorelease];
exploreViewController.title = @"Explore";
UIViewController *dialerViewController = [[[DialerViewController alloc] initWithNibName:@"DialerViewController" bundle:nil] autorelease];
dialerViewController.title = @"Dialer";
self.tabBarController = [[[UITabBarController alloc]init]autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:searchViewController, exploreViewController, dialerViewController, nil];
[self presentModalViewController:tabBarController animated:YES];
}
Don't forget to create the corresponding nib files(dialerViewController.xib, SearchViewController.xib, DialerViewController.xib) and make these views hight to 411px(this is unto you)
thanks
first of all, i don't think pushing a tab bar as a subview as a good idea
but if you still want to do this, there's a lot of way to work around
one of them is by using modalview
first you have to add this code after you make the button
it attach an event listener to the button you have
next, you make the event function to do the tab bar pushing
and dont forget to import the tabbarcontroller class header file in your .m
hope this help ;)
edit : if you need to go back from the tab bar view into the previous menu, you can add a button, give it an event listener, and put this code inside the function