0

when the app is launched, i have placed a view controller(login) after validating the field it is redirected to tab bar controller. The problem is i have to place logout button and when clicking logout button it should go to the root view controller(login page). I have tried pushing from tab bar controller to root view controller, it is pushed but still facing few tab bar issues while proceeding further. How can i pop/push to root view controller from tab bar item ?

Rahul Lalit
  • 416
  • 2
  • 10
Gowtham
  • 327
  • 8
  • 17
  • check this [Link](http://stackoverflow.com/questions/2716755/showing-login-view-controller-before-main-tab-bar-controller?rq=1) and add didLogoutFinished: Method – Rahul Lalit Jul 27 '12 at 14:41

4 Answers4

2

I'd imagine in your AppDelegate.m, You have created a navigation controller with the LoginUIViewController as the RootViewController.

You could solve the problem like this:

For example, you have a FirstTabUIViewController in your TabBarController, you want to go back to your LoginUIViewController (your RootViewController) from the FirstTabUIViewController.

  1. Create a reference to your TabBarController in the FirstTabUIViewController.h and .m

    @property (strong, nonatomic) IBOutlet UITabBarController *tabBarController;

    @synthesize tabBarController = _tabBarController;

  2. Create a method handles "LogOut" button click in .m

    -(IBAction)logoutBtnTapped:(UIBarButtonItem *)sender{

    [self.tabBarController.navigationController popToRootViewControllerAnimated:YES];

    }

That it is! Hope that helps :)

TS.xy
  • 1,244
  • 2
  • 13
  • 29
0

May be you can use UINavigationController for root view controller http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

There are some examples about custom back buttons. If you want to use default back button you can rename as logout and give an action on it.

Just an idea.

Tuna Karakasoglu
  • 1,262
  • 9
  • 28
0

You just need to place the login screen in appdelegate window again when you clicked the logout button.

LoginViewController *loginVC = [[LoginViewController alloc]init]; 
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.window setRootViewController:loginVC];// This will initiate the login screen again
Pang
  • 9,564
  • 146
  • 81
  • 122
Nischal Hada
  • 3,230
  • 3
  • 27
  • 57
0

This works fine for me in same case,

ChooseStateViewController *loginVC = [[ChooseStateViewController alloc]initWithNibName:@"ChooseStateViewController" bundle:nil]; 

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:loginVC];
[nc.navigationBar setTintColor:[UIColor blackColor]];
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
[appDelegate.window setRootViewController:nc];
BADRI
  • 643
  • 8
  • 26