Login View with SWRevealViewController - ios

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!!!

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.

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.

#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?

To solve this problem I used following steps.
Create a ViewController in Storyboard with type "SWRevealViewController" and make it as "initial view controller".
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.
After Login the view you want to show side drawer add toggle button.
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.

Related

iOS slide-menu - Objective-c

In my project I have existing side menu i.e swrevealviewcontrtoller to display right side menu.It is working correctly. I want to add second right menu in between the project using slideNavigationController. This is the screen shot of my storyboard. I can not touch existing base code and Before login page I want to add slideNavigationController to display another right sidemenubar.
i.e not my root view controller for that I referred these two links.SlideNavigationController,Solution for making rootviewcontroller
StoryBoard Image
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
LoginViewController *loginView = (LoginViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: #"Login"];
[loginView setModalPresentationStyle:UIModalTransitionStyleCrossDissolve];
SlideNavigationController * slideNavCtl = [[SlideNavigationController alloc] initWithRootViewController:loginView];
[self.window setRootViewController:slideNavCtl];
It is taking LoginViewController as root view controller.
As we are using SwrevealViewController at the first it contains modal segue so I am not able to display the right menu in login view controller. After adding that code in app delegate I am able to display right menu in loginpage but login page is the rootview but I want splash screen as a rootViewController. Using SlideNavigationController I want to display another right menu in login .

SWRevealViewController project in iOS

Note: Problem solved.
Here comes the story. I am using RevealViewController in my project. I am also hiding the navigationBars:
[self.navigationController setNavigationBarHidden];
My project can be seen in the picture below and the "menuButton" is implemented in the tabBarViewController.
Since the navigationBar is hidden due to my interface looks, all tabViews (HomeViewController) will not show the menuButton and the navigationBar as supposed to. I am not using panGestureRecognizer to trigger the menu aswell.
This means I have a problem to trigger the menu via a normal button in HomeViewController. The menuButton-event is placed in tabBarViewController.m:
_menuButton.target = self.revealViewController;
_menuButton.action = #selector(revealToggle:);
So I tried to call a method from HomeViewController to fire the button in tabBarViewController like this:
HomeViewController.m
- (IBAction) onMenuClicked: (id)sender{
tabBar = [[tabBarViewController alloc] init];
[tabBar setupMenu]:
}
tabBarViewController.m
-(void) setupMenu{
[_realMenuButton sendActionForControlEvents:UIControlEventTouchUpInside];
[_realMenuButton addTarget:self.revealViewController action:#selector(revealToggle:) UIControlEventTouchUpInside];
}
In this example I tried to make the realMenuButton and normal UIButton. Ive also tried as a UIBarButtonItem just to trigger the #selector(revealToggle:) But nothing happens in the app when I try to trigger the button from HomeViewController.
Not sure how I shall make this work. Any other Ideas or tricks? Please be specific if so! Regards
Yes, it will still work.
SWRevealViewController is just a subclass of a UIViewController, so you can use it at any point in the app:
By calling presentViewController:animated at some point.
By using it in a navigation stack etc.
Note that you can add gestures from SWRevealViewController to its content view controllers, which will alter the behaviour of used in a navigation view controller, but that's to be expected, and you still have full control over its behaviour.
Edit
The UI structure of your app is still not clear to me - it looks like you're trying to call revealToggle on an instance of SWRevealViewController when the VC in view is infact HomeViewController? How would this work, when SWVC is not even in view?
My best guess is that your UI structure should be as follows:
TabBarController --->(root)UINavigationController --->(root)SWRevealViewController.
Then, on your SWRevealViewController, set HomeViewController as the front view controller, and the TableViewController as the right or left view controller.
Do you mean like this?
it is possible. you can set the menu button in your tabBarController.m, like this :
UIBarButtonItem *menu = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"menu.png"] style:UIBarButtonItemStylePlain target:revealController action:#selector(revealToggle:)];
self.navigationItem.leftBarButtonItem = menu;
self.delegate = self;
For me, my initial view controller is the login screen (obviously I don't need reveal any VC here...). then when user tap the login button,
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:yourRootVC];
LeftMenuViewController *leftMenuVC = [[LeftMenuViewController alloc]init];
SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:leftMenuVC frontViewController:nav];
revealController.delegate = self;
[self presentViewController:revealController animated:YES completion:nil];
I've tried it and it should work as normal. Even it isn't initial view controller

Is it possible to wrap the rootViewController within another ViewController?

Right now I'm attempting to integrate this library with an existing app. However, the app already has a rootViewController. Is it possible to simply redirect the frontView this library requires to the current rootViewController that the app has? All I need to implement is the ability to swipe between the rearViewController and the frontViewController like in the first example the library gives.
Yes, but then you need to set the SWRevealController as the new rootViewController.
Here's some sample code to illustrate from application: didFinishLaunchingWithOptions: in your app delegate:
MYAppViewController *mainVC = [[MYAppViewController alloc] init];
// Before using SWRevealViewController I had this line:
// self.window.rootViewController = mainVC
// Used for the rear view of the SWRevealViewController
MYMenuViewController *menuVC = [[MYMenuViewController alloc] init];
SWRevealViewController *revealVC = [[SWRevealViewController alloc] initWithRearViewController:menuVC frontViewController:mainVC];
// Now set the SWRevealViewController as the root view controller
self.window.rootViewController = revealVC;
Just make your rootViewController class inherit from SWRevealViewController, then you wont need to wrap anything.
read the Documentation it explains what to do. You don't need to wrap anything.

IOS - Objective C - How do I remove Tableview Menu from my Login View Controller?

In my iOS Project, there is a login ViewController that sends the user to a TabViewController if he has the right credentials.
This TabViewController has 5 tabs, the fifth one is for Logout, which send the user back to the Login ViewController, and of course clears out the already filled credentials of the user.
My problem is that i have the menu of the TableView shown in my Login page.
How to i get rid of this menu in my Login ViewController page ?
I use Xcode6 & Objective-C
if you need any further explanations/source code of my problem, feel free to ask.
note:
In the beginning, I mean when the Login ViewController is first shown to the user, the menu doesn't show.
It turns out that whole UI architecture of your app is based on the UITabBarController. However it is not very good practice in your case. I would like to suggest you add separate modal controller for presenting login page.
Try:
self.tabBar.hidden = YES;
Assuming that you are using a storybaord I have the given solution
I created a sample application and tried replicating your issue, so here's the look at my storyboard
The way i designed it i have a separate login view controller and two view controller (Menu List and Logout) which are embedded in a tabbar controller.
If you're new to storyboard then embedding viewControllers with tabbarController is pretty much straight forward, you select the view controller first and then go to the editors menu in Xcode
Alright now coming back to business, code which i added on the IBAction of the login screen button is given below where MainTabbar is the storyboardID of the TabMaster controller
AppDelegate *appdel = [UIApplication sharedApplication].delegate;
UIStoryboard *storyBoard = appdel.window.rootViewController.storyboard;
TabMasterController *tabController = [storyBoard instantiateViewControllerWithIdentifier:
#"MainTabbar"];
[appdel.window setRootViewController:tabController];
When i executed the application everything was OK and I was able to see the tabbar items after I hit the action button on login screen
Now its time to write some code for the logout tabbar item, so I selected the view controller assigned to the Main tabbar controller and added the delegate mentod of UITabbarController which looks some what like this
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
// Since i have two tabbar items 1 generally means logout in my case
if (tabBarController.selectedIndex ==1) {
AppDelegate *appdel = [UIApplication sharedApplication].delegate;
UIStoryboard *storyBoard = appdel.window.rootViewController.storyboard;
ViewController *tabController = [storyBoard instantiateViewControllerWithIdentifier:
#"LoginVC"];
[appdel.window setRootViewController:tabController];
}
}
LoginVC is the storyboardID of the Login View controller
After adding the above code when i used to tap on the logout tabbar item I was able to go back to the login screen in my storyboard.
Hope that helps.
Either you can add tab bar item programmatically or you can add in storyboard
If programmatically then add like
self.tabBarController.viewControllers = [NSArray arrayWithObjects:
[[UINavigationController alloc] initWithRootViewController:self.myContactsController],
[[UINavigationController alloc] initWithRootViewController:self.searchController],
[[UINavigationController alloc] initWithRootViewController:self.registrationController],
[[UINavigationController alloc] initWithRootViewController:self.loginController], nil];
Set tabbarController as initial view controller in storyboard
After checking login credential, On success
// to get list of current tab bar items
NSMutableArray *tbViewControllers = [NSMutableArray arrayWithArray:[self.tabBarController viewControllers]];
// to remove tab bar items using index value
[tbViewControllers removeObjectAtIndex:3];
[tbViewControllers removeObjectAtIndex:2];
// to add tab bar items
[tbViewControllers addObject:[[UINavigationController alloc] initWithRootViewController:self.myProfileController]];
[tbViewControllers addObject:[[UINavigationController alloc] initWithRootViewController:self.logoutController]];
// to set pre selected tab bar item
self.tabBarController.selectedIndex=2;
// set array items in tab bar
[self.tabBarController setViewControllers:tbViewControllers];
Fixed it, it's not the optimal solution but it worked for me:
what I did is :
1- I deleted the Tab Bar Item from my Login ViewController
2- I inserted a logout button in my table view screens
3- I added segues from my Table view screens to the login screen in my storyboard.
This way if the user clicks on the logout button , he will be directed to the login screen & cannot go back where he was unless he enters his credentials.

Pop SWRevealViewController

I'm using SWRevealViewController to build a sliding menu. Before accessing the menu, a login view is displayed to allow the user login. Now i want to let the user disconnect and display the login view again. My question is how to pop the SWRevealViewController.
code that provides access to application after login is:
MainViewController *vMainMenu = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
vMainMenu.strURL = URL;
LeftMenu *vLeftMenu = [[LeftMenu alloc] initWithNibName:#"LeftMenu" bundle:nil];
UINavigationController *principalNavController = [[UINavigationController alloc] initWithRootViewController:vMainMenu];
UINavigationController *rearNavController = [[UINavigationController alloc] initWithRootViewController:vLeftMenu];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavController frontViewController:principalNavController];
mainRevealController.delegate = self;
self.viewController = mainRevealController;
principalNavController.navigationBar.hidden = YES;
rearNavController.navigationBar.hidden = YES;
self.window.rootViewController = self.viewController;
This solution is not working:
[self.revealViewController.navigationController popViewControllerAnimated:YES];
Splash *vSplash = [[Splash alloc] initWithNibName:#"Splash" bundle:nil];
[self.navigationController pushViewController:vSplash animated:YES];
Can you help me please
Thank you.
You can't go back to your LoginViewController by pop. You can add PresentViewController without animation to do this.
Splash *vSplash = [[Splash alloc] initWithNibName:#"Splash" bundle:nil];
[self presentViewController: vSplash animated:NO completion:nil];
I had the same issue. I have implemented several storyboards.
let storyboard = UIStoryboard(name: "Login", bundle: nil)
let startcontroller = storyboard.instantiateViewControllerWithIdentifier("LoginVC") as UIViewController
window?.rootViewController = startcontroller
With this snippet you can access the right View Controller.
You can use an "Unwinding Segue". The unwinding segue is like a regular segue which goes back instead of forward.
First, go to the Login View Controller and add the following method:
-(IBAction)unwindToLoginScreen:(UIStoryboardSegue *)segue {
}
The method may be empty and it can have any name; it is good to use descriptive names because you might have many unwind segues on your code and it will be useful to be able to distinguish between them.
This unwind method will act as a global constant that will be visible to all View Controllers on the storyboard.
Now, on each view controller that should be able to return to the Login Screen you create a Unwind Segue. You can do this on the Storyboard:
Select the View Controller you want; on the top bar you should see three buttons, one representing the View Controller, another representing the First Responder and another representing an Exit.
Ctrl+Drag from the View Controller button to the Exit button. A context menu will appear and will list all visible unwind methods you created on your storyboard.
On the Document Outline, an "Unwind segue" will appear for the view controller. You can add an identifier to that segue (such as "Login" in your case). Then you call performSegueWithIdentifier. Select the one you created on your Login view controller.
Doing this, the complete stack between the view controller and the login view controller will be unwinded. That is, all view controllers stacked above the Login view controller will be popped.
You can also use prepareForSegue for the unwind segues the same way you would use them for regular segues. And you can add code to the -(IBAction) method if you want to do something as a result to the segue.

Resources