1

I understand this question is many times on STackOverflow and also many on internet too. I have also asked question related to be same, but the context is different, so please bear with me as I am not able to find the solution for this task.

I am using Xcode 5, using Storyboard. MY project is Tab based and have added a LoginViewController in the storyboard. My win is to show LoginViewController prior to Tabs. I tried several ways from various sites, but nothing works fully. With this code, I could get the LoginViewController at first, but not able to get Tabs controller. In my AppDelegate :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.    
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
self.tabBarController = [[MC_MainTabBarController alloc] init];

LoginViewController *loginViewController = [storyboard instantiateViewControllerWithIdentifier:@"loginViewController"];
[self.window setRootViewController:loginViewController];

// This also works - it shows the login
//[[[[UIApplication sharedApplication] delegate] window] setRootViewController:loginViewController];

// With this Login doesn't come only
//[loginViewController setModalPresentationStyle:UIModalPresentationFullScreen];
//[tabCtrler presentViewController:loginViewController animated:NO completion:nil];

return YES;
}

In my LoginViewController.m - on loginBtnClicked event in end, I call :

    NSLog(@"Showing TabController");
MC_AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.window setRootViewController:appDelegate.tabBarController];

On execution of the above lines, I get black screen and following warning :

Showing TabController
Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation.
Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation.

Can anyone please help me out. I am stuck on this problem from last 2 days.

Any help is highly appreciated.

Tvd
  • 4,463
  • 18
  • 79
  • 125
  • 1
    Maybe my answer could help you: http://stackoverflow.com/questions/19962276/best-practices-for-storyboard-login-screen-handling-clearing-of-data-upon-logou/21877460#21877460 – Dimitris Bouzikas Feb 28 '14 at 10:24
  • @dimimpou, Thanks a lot. Your answer helped me out. Also got notification idea. Though I implemented Trevor Gehman's answer for my question, but adopted ideas from your answer too. Thank you. – Tvd Feb 28 '14 at 11:47

1 Answers1

2

Are you sure MC_MainTabBarController is a subClass of UITabBarController? (I guess it is) because this error can appear when the TabBar is not the rootViewController

Instead of [[MC_MainTabBarController alloc] init]; i would allocated the tab bar controller from storyboard [storyboard instantiateViewControllerWithIdentifier:@"myTabBarIdentifier"];

I try and it worked for me :

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    _tabController = [storyboard instantiateViewControllerWithIdentifier:@"tabbcontrolllerid"];
     LoginViewController *login = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
    [_window setRootViewController:login];
    return YES;
}

And like you in the button of login

- (IBAction)goToApp:(id)sender {
    stackAppDelegate *app = [UIApplication sharedApplication].delegate;
    [app.window setRootViewController:app.tabController];
}

For info the tab bar is a custom TabBarController which is a subclass of UITabBarController And i have set in the storyboard the identifier of my custom tabbar.

Fogia
  • 127
  • 1
  • 8
  • Thanks for quick solution. Yes init ing my tabController was the problem. I implemented that method and it does work. Though I implemented as Trevor Gehman showed in dimimpou link to the answer, but the concept is as you mentioned - gave storyboardId to TabController and initialized thru storyboard. Thanks once again. – Tvd Feb 28 '14 at 11:50