Question

I've followed the TreeHouse tutorial on how to create a login/signup screen as well as the AppCoda tutorial for adding a sidebar navigation menu: http://www.appcoda.com/ios-programming-sidebar-navigation-menu/

I have the login/signup bar attached to my master viewcontroller which is hooked up to the sidebar viewcontroller. This makes for a funny bug where I can get to the main screen without logging in.

Can anyone suggest a storyboard layout where I can make the sidebar slideable only when I'm logged in?

GIF of bug

My Storyboard layout

Was it helpful?

Solution

In your LoginController (or what name) add this line in viewDidLoad:

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

it will stop default pan gesture for popup. Try it.

OTHER TIPS

The way I have usually worked with this issue is to have another viewController that handles the login which is not part of the main app navigation.

The login controller can then do whatever it needs to login and do something like this after user is authenticated:

-(void) loginDidComplete {

    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kLoginKey];
    AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
    appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard"
                                                                           bundle:[NSBundle mainBundle]]
                                                 instantiateInitialViewController];


    [[NSNotificationCenter defaultCenter] postNotificationName:@"UserDidLogin" object:nil userInfo:nil];

}

And in the app delegate's application didFinishLaunchingWithOptions, we can check if user is logged in by doing this:

if ([User userAuthenticated] ) //if user is auth correctly, then we go to the main view
{
    self.window.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard"
                                                                bundle:[NSBundle mainBundle]]
                                      instantiateInitialViewController];
}
else //otherwise we show the login controller
{
    self.window.rootViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard"
                                                                bundle:[NSBundle mainBundle]]
                                      instantiateViewControllerWithIdentifier:@"LoginViewController"];
}

added a screenshot to demonstrate the 2 viewcontrollers in storyboard

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top