I followed parse.com tutorials on how to implement login + register + segue to main controller if registration or login is successful. This works beautiful.
I then wanted to implement a side navigation using SWRevealViewController. I followed APPCODA link on this and got it working only when "SWRevealViewController" is the initial view controller.
When i have my parse login controller as initial i can't see anything from the navigational controller aka "SWRevealViewController."
how would i be able fix this, make my login/register controllers the initial controllers and still be able to have SWRevealViewController when login/register is successful?
i would appreciate any help or pointers.
below is my APPDelegate.m
#import "AppDelegate.h"
#import <Parse/Parse.h>
#import <GoogleMaps/GoogleMaps.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
LoginView *lv = [[LoginView alloc]init];
SidebarViewController *sbvc = [[SidebarViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:lv];
UINavigationController *menuVC = [[UINavigationController alloc]initWithRootViewController:sbvc];
SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:menuVC frontViewController:nav];
revealController.delegate = self;
self.menu = revealController;
self.window.rootViewController = self.menu;
[GMSServices provideAPIKey:@"XXXXXXXXXX"];
[Parse setApplicationId:@"XXXXXXXXXXXXX"
clientKey:@"XXXXXXXXXXXXX"];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
return YES;
}
In apps with user sessions, it is usually best to keep login/signup on a separate view hierarchy from the rest of the app and present the internal structure if there is an active session. You can achieve this by checking for
[PFUser currentUser]
as it will return nil
if the user is not logged in.
Provide a check in your AppDelegate like so:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// .. Rest of your initialization code
if ([PFUser currentUser]) {
// Let's pop them right to the home screen
[self showHomeScreen];
}
else {
// Present login vc
LoginView *lv = [[LoginView alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:lv];
self.window.rootViewController = nav;
}
return YES;
}
- (void)showHomeScreen {
SidebarViewController *sbvc = [[SidebarViewController alloc] init];
UINavigationController *menuVC = [[UINavigationController alloc] initWithRootViewController:sbvc];
UIViewController *home = [[UIViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:home];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:menuVC frontViewController:nav];
self.window.rootViewController = revealController;
}
Then, by including
- (void)showHomeScreen;
in AppDelegate.h
, you can call this method upon successful registration/login:
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate showHomeScreen];