1

I am using RESideMenu in my application. But I need to add login and registration viewcontrollers before the RESideMenu.

Is it possible, if yes then how can I do that ?

Thanks in advance.

Abhijith G
  • 244
  • 1
  • 8
  • I would add a modal view controller above it. It is, in my opinion, the best practice to build a login view. – Asaf May 11 '15 at 20:03

2 Answers2

0

There are many ways to do this. The most common is you have a loginView controller and then in the app delegate you can write something like this in the app delegate:

if([[NSUserDefaults standardUserDefaults] valueForKey:@"AlreadyLogin"])
        {
      // So, here user already login then set your root view controller, let's say `SecondViewController``
      SecondViewController *secondViewController = [storyBoard instantiateViewControllerWithIdentifier:@"SecondViewController"];
      // then set your root view controller 
      self.window.rootViewController = secondViewController;
    }
else
{
     // It means you need to your root view controller is your login view controller, so let's create it 
     LoginViewController  *loginViewController= [storyBoard instantiateViewControllerWithIdentifier:@"LoginViewController"];
     self.window.rootViewController = loginViewController;
}

Credit: Skip view if user already logged

Community
  • 1
  • 1
Mika
  • 5,807
  • 6
  • 38
  • 83
0

Yes it is very possible.

Solution A:

After successful login/sign up, do:

[UIApplication sharedApplication].window.rootViewController = [[RESideMenu alloc] init...];

Solution B:

Place your login/signup view controllers in the main content portion of the RESideMenu, and disable the two side menus until the user is signed in.

Solution C:

Embed the RESideMenu in a UINavigationController and optionally hide the navigation bar.

For more info I recommend researching "view controller containment" as that is the pattern used by RESideMenu, UINavigationController, and other types of "container" view controllers.

I hacked together a quick example of Solution C and it seems to work fine:

@implementation LoginViewController

- (void)viewDidLoad {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(50, 50, 100, 100);
    [button setTitle:@"Login" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(goToRESideMenu) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

    self.navigationController.navigationBarHidden = YES;
}

- (void)goToRESideMenu {
    UIViewController *redViewController = [[UIViewController alloc] init];
    redViewController.view.backgroundColor = [UIColor redColor];
    UIViewController *greenViewController = [[UIViewController alloc] init];
    greenViewController.view.backgroundColor = [UIColor greenColor];
    UIViewController *blueViewController = [[UIViewController alloc] init];
    blueViewController.view.backgroundColor = [UIColor blueColor];

    RESideMenu *sideMenu = [[RESideMenu alloc] initWithContentViewController:redViewController
                                                      leftMenuViewController:greenViewController
                                                     rightMenuViewController:blueViewController];
    [self.navigationController pushViewController:sideMenu animated:YES];
}

@end

The result looks like this:

demo

tboyce12
  • 1,449
  • 14
  • 28