37 Comments

  1. Hi, nice work! I was working on implementing the SSO login using facebook api. My idea was to show the FBLoginView before transitioning to the tabBarController. If possible, could you please show me how you could do this as well.

  2. Hi Kenta, Thanx for your comment. Actually it would be a bit different with FBLoginView, I assume you are following this facebook guide https://developers.facebook.com/docs/ios/login-tutorial/#permissions-login

    So you need to implement the delegate method `loginViewShowingLoggedInUser:`
    This delegate method will be notified whenever the user is logged in, at that moment, you can make the transition to the tabBarController:

    FBLoginView *loginView = [[FBLoginView alloc] init];
    loginView.delegate = self;//Don’t forget to set the delegate to self in order for the delegate protocol methods to be notified
    //implement the following delegate method
    – (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
    //here perform the transition to tabBarController
    }

    Let me know πŸ™‚

    Malek

  3. Hi Malek, Thanks for this tutorial. I am really struggling to get my Login screen before tab controller. Followed your tutorial, I could get the login screen, but the Tabs doesn’t appear now. I am using storyboard, added everything in AppDelegate & LoginViewController loginBtnClicked event as you have described. My didFinishLaunchingWithOptions code : UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@”Main_iPhone” bundle:nil];
    self.tabBarController = [[MC_MainTabBarController alloc] init];
    LoginViewController *loginViewController = [storyboard instantiateViewControllerWithIdentifier:@”loginViewController”];
    [self.window setRootViewController:loginViewController];

    And loginBtnClicked method contians :
    NSLog(@”Showing TabController”);
    MC_AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    [appDelegate.window setRootViewController:appDelegate.tabBarController];

    I get black screen & the messages on execution of above code :
    Showing TabController
    2014-02-28 12:06:09.536 MintChat[483:70b] Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation.
    2014-02-28 12:06:09.537 MintChat[483:70b] Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation.

    I am using storyboard, so haven’t implemented the tab code on my own – what these error can be. I am using Xcode 5. Can you please help me with this. From last 3 days I am struggling with this issue and yet am not able to solve it to the best. I would highly appreciate it if you can help me out. Thanks lot.

  4. Hi julie,

    Are you sure the tabbarcontroller is a “root” in your storyboard scene ? the error you got usually indicate there is a previous controller insterted before the tabbarcontroller (UINavigationController for instance).

    UITabBarController should always be used as a root controller, so in the storyboard, make sure no controller is before it.

    Let me know.

  5. Oh sorry, I had missed your answer. Anyways, yes tabbarcontroller is the root in my storyboard. My application is a Tabbed template application.

  6. Julie, do you mind sharing your code solution for this? I’m having the same trouble

  7. Thanks for posting this article. I’m a newbie at developing on the ios platform. I used about a couple hours trying figure out how to implement the slide menu with login storyboard preceding. This post help me indirectly figure out how to accomplish that task.

  8. Hi !

    Thanks for this article.

    Do you have it using XCODE 6 and Swift?

    Thank you again!

  9. Is it possible to go back to the login screen after we’ve changed the root view controller? There isn’t any navigation structure that allows the user to go “back” to the login screen.

  10. Hello πŸ™‚

    Moving back to login screen is as simple as moving forward from login screen to tabbar screen. You just need to tell the window that its root is now the login view controller. Here is:

    LoginViewController *loginVC = [[LoginViewController alloc]init];
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    [appDelegate.window setRootViewController:loginVC];// This will move you to login screen

  11. Thanks. Will this create a new instance of LoginViewController and cause memory leak??

  12. Yes it will create new instance, yet it is safe from memory leaks πŸ™‚

    But if you want, you can declare the loginVC as a property in your class scope so that it’s declared once, and use it as self.loginVC

  13. Hi !

    I have the same problem , I am using storyBoard on Xcode 6. Please give me a solution for the same. If possible can you please demonstrate it as you have done it earlier.

    Thanks in advance.

  14. how can i make the transition more smooth when setting the root view controller. Like with segue based animations

  15. Hi everyone,

    What if we push UITabBarController to navigationController ?

    Its working fine for me, Is there any problem ?
    Thanks

  16. Hi Muhammad πŸ™‚
    Such implementation is not recommended even if it’s working. UITabBarController should be the root of your app window and shouldn’t be a root (or in the stack) of a UINavigationController. Instead, you better try to mimic a tab bar controller, so it would be a UIViewController but with custom views as tabs.

  17. I am having a trouble using your method of setting loginVC as root and then Tabbar as root when the user submit the login details correctly.
    Problem is that when the app is run login screen and related screen of login (i.e SignUp/Forgot password etc). are shown first perfectly as you describe but in the backend tab bar is also running. As it is not showing on the screen but it is running.
    I have set a timer on one the screen in Tab bar and set a Timertime 10 seconds.
    When i run the app it takes near about 10 seconds to submit details and click submit. and when i submit and tabbar is loaded the timer has been terminated.
    How to stop tabbar to run parallel with loginVC. I want to run tabbar after the submission of correct login details.
    Is there any way???

  18. I have got my solution by debugging. Tabbar should alloc and init and assigned as root view controller in a special function other than Application didfinishLaunchingWithOption and in the loginVC when your login submission detail are correct instead of setting tabbar as root view controller just invok that function which contain the code related to tab bar allocation, initialisation and assignment as root viewcontroller..

    This will tell the tab bar to load when that function is invoked.
    While in your case both loginVC and Tab bar are running at the same time because they have been initialised at the same place and at the same time.

  19. Hi Syed,
    Sorry, you are wrong about my code. First off, there is absolutely no problem in assigning the tab bar, as the root of the window, INSIDE the didFinishLaunching app delegate method. Second, the tabbar and loginVC are not running at the same time because there is ONE AND ONLY ONE object which is assigned as the root of the window at a time.
    Anyway, glad you solved your issue! Keep visiting!

Comments are closed.