4

Currently, I have a project where I want to integrate a Login View with a SideBarRevealController.

Here is the link with the SideBarRevealController : https://github.com/John-Lluch/SWRevealViewController

I am currently having an issue presenting my login view which is a standard UIViewController.

There are 3 example projects in the link, but I am going to stick with the first one, for IOS. I am having an issue understanding which viewcontroller (SWRevealViewController or my loginview controller) should be the rootviewcontroller?

I figure SWRevealViewController should be the rootviewcontroller but I am not completely sure.

I guess my understanding of how to design the flow of my application with a login view and a mainview is off.....

But if possible, how would I allow a login view to be presented before the SWREVEALVIEWCONTROLLER class, which contains several viewcontrollers?

If there are any questions or concerns please refer to the link and run the example project. I figure this would be an issue for EVERYONE who wants a login view with a sidebar navigator feature.

THANK YOU STACKOVERFLOW!!!

jsetting32
  • 1,632
  • 2
  • 20
  • 45

4 Answers4

2

For adding a login screen before the SWRevealViewController you will have to make the changes in the AppDelegate.m file.

LoginView *lv = [[LoginView alloc]init];

SideMenuViewController *smvc = [[SideMenuViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:lv];
UINavigationController *menuVC = [[UINavigationController alloc]initWithRootViewController:smvc];

SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:menuVC frontViewController:nav];
revealController.delegate = self;

self.menu = revealController;
self.window.rootViewController = self.menu;

By this you will get a loginview as your rootview and from there you can navigate to next screen from where you will use sidemenu actions.

Hiren
  • 676
  • 7
  • 21
0

I am also using the SWRevealViewController for side menu. I also has the similar requirement, where to show a login screen for existing user and new user registration scree. The way I solved this problem is using multiple storyboard. A very clean and easy solution. I have a login storyboard and main storyboard file. In your project setting, disable loading from storyboard, by removing the storyboard key. Now in your application didFinishLaunchingWithOptions, check if user is already logged in, then load Main storyboard, else load login storyboard. Now all left is dismissing and showing other story, as when required.

cocoaNoob
  • 449
  • 11
  • 22
  • 1
    I have a similar setup. Your solution sounds interessting. How do you correct *disable loading from storyboard*? Where do I find the *storyboard key*? The Problem I currently have, if I do a logout (which is in the SWRevealViewController) and have to switch to the login.storyboard I get the error message `Warning: Attempt to present on `. How do you do you make your logout? – jerik Mar 26 '14 at 11:38
  • The thing is when you make a dynamic decision, then that particular storyboard root view controller becomes your app root view controller. In such case, when you want to replace your window root view controller to loginVC, when logout happens, and similarly when login happens changed it again. – cocoaNoob Mar 27 '14 at 03:04
  • For removing default storyboard, go to target, deployment Info, then under Main interface, you will see the list of storyboard, which you can edit. – cocoaNoob Mar 27 '14 at 03:06
  • Another Simple solution will be to have your login storyboard as always main storyboard. Then in your loginVC, you decide if user is already logged in or not, if so then modally present your main storyboard, but without animation – cocoaNoob Mar 27 '14 at 03:14
  • > login storyboard as main storyboard. I had this before, the issue is, that if you are logged in you always go the step over the login storyboard and this takes time. If you do that often it is anoying. will check your solution, and if it works upvote :) Hopefully the next month. – jerik Mar 27 '14 at 15:19
  • I do have a sample code for this kind of setup, if you are interested do let me know – cocoaNoob Mar 28 '14 at 06:16
0

@Hiren

SideMenuViewController *smvc = [[SideMenuViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:lv];
UINavigationController *menuVC = [[UINavigationController alloc]initWithRootViewController:smvc];

SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:menuVC frontViewController:nav];
revealController.delegate = self;

self.menu = revealController;
self.window.rootViewController = self.menu;

so what you are saying is that 1v = whatever the name of your login controller is?

Miguel
  • 333
  • 2
  • 13
0

To solve this problem I used following steps.

  1. Create a ViewController in Storyboard with type "SWRevealViewController" and make it as "initial view controller".
  2. First view that is connected to SWRevealViewController with segue "sw_front" do not add toggle button to show drawer. Implement login process on this first view.
  3. After Login the view you want to show side drawer add toggle button.
  4. For logout add following line of code. self.revealViewController().performSegue(withIdentifier: "sw_front", sender: self)

As it is quite hard to explain i have draw a flow how I implemented it. enter image description here