Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I connect Button Action to Tabbar Viewcontrollers

I am new to iPhone development. I am developing a TabBarViewcontroller App (iPhone and iPad) and in that I've created one LoginViewController and a Button Action. My expectation is after clicking that Button, the control will move from LoginViewController to TabBarViewController. In this TabBarViewcontroller I have 5 Tabbar (items) ViewControllers. Is it possible?

If you can, please share your ideas.

like image 731
GR. Avatar asked Nov 20 '12 09:11

GR.


2 Answers

First of all, take UINavigationController and UITabbarController in your MainWindow.xib and bind IBOutlet to respective fields.. ans set LoginViewController as rootViewController of your UINavigationController..

Then in didFinishLaunchingWithOptions method write this..

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [self.window setRootViewController:navController];
    [self.window makeKeyAndVisible];    
    return YES;
}

Now create other method in AppDelegate.m like this..

-(void)loadApplication
{
    [navController pushViewController:tabbarController animated:NO];
}

On your Login button action.. call this method as follows..

-(IBAction)btnLoginTapped:(id)sender
{
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    [appDelegate loadApplication];
}
like image 69
Mehul Mistri Avatar answered Oct 13 '22 10:10

Mehul Mistri


So in button action try following codes

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; 
appDelegate.window.rootViewController = tabBarController;
like image 38
Susim Samanta Avatar answered Oct 13 '22 10:10

Susim Samanta