2

I am developing an app that use MFsidemenu for the swipeBar. My app consists of a loginController which is an uiViewController and after logging it change into an uiNavigationController.

MFsidemenu need this code running on the AppDelegate:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;

UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:@"leftSideMenuViewController"];
[MFSideMenu menuWithNavigationController:navigationController
                  leftSideMenuController:leftSideMenuViewController
                 rightSideMenuController:nil];

The problem is how to change the second line of the code if the initialView is an uiViewController(Login) and after that, how to pass it to the secondViewController(MainMenu) which is an uiNavigationController?

In a shortway, I want the MFSidemenu to work only on the secondController, which is the main controller. Thanks!

Updated: solved, by SpaceDust solution below :)

Question Update: So the example of using MFSidemenu only limited to showing a sidemenu on the controller. The example sideMenuController exiled from any other segue on the storyboard. on the sidemenu I implemented uiTableViewController to navigate to another controller. So how to change MainMenuView with sideMenuController didSelectRowAtIndexPath? I hope my english good enough to represent my situation though. Thanks once again!

xeravim
  • 463
  • 7
  • 20
  • 1
    why dont you make your `navigationcontroller's rootviewcontroller` the `uiViewController(Login)` ? – SpaceDust__ Apr 03 '13 at 13:49
  • because i dont want the swipebar work on the loginController. i want it work only on main menu which is the secondController. any idea? – xeravim Apr 04 '13 at 03:07

1 Answers1

3

You need to present your uiViewController(Login) as a modal view controller if you dont want to side menu appear during login.

Create a login viewcontroller in storyboard, give it a storyboard id lets say LoginViewController . Dont connect that viewcontroller to anything on storyboard let it sit a corner by itself.

first create a global singleton variable where you check if user is logged in

then In your navigationcontroller's rootviewcontroller

-(void)viewWillAppear:(BOOL)animated
{
     //this will present the login view if user is not logged in
    if (isLoggedIn==NO) {

        UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                     bundle:nil];
        LoginViewController *loginVC = [sb instantiateViewControllerWithIdentifier:@"LoginViewController"];
        [self presentModalViewController:loginVC  animated:YES];

    }
}

in your login viewcontroller when login process is complete change global singleton bool to isLoggedIn=YES then dismiss your login view controller.

[self dismissViewControllerAnimated:NO];

SpaceDust__
  • 4,844
  • 4
  • 43
  • 82
  • everything works perfect man! thanks! but i stumble on another issue here. gonna update my question above. :) – xeravim Apr 05 '13 at 10:11
  • @AlvinResmana to update your `mainmenuview` from tableviewcontroller you need to create a `delegate pattern method` and call it when `didSelectRowAtIndexPath`, this is entirely a new question create another question for updating `mainmenuview`, dont update this question because your problem is solved – SpaceDust__ Apr 05 '13 at 17:20
  • thank you @SpaceDust. I'll create another one. sorry for updating, did not know about the rules. – xeravim Apr 05 '13 at 18:23