Search code examples
iphoneios6storyboard

loginviewcontroller before the tabviewcontroller which includes SideMenuController


Following the storyboard

Problem: I have a tabViewController which includes four tabs and at the 1st tab is the homeViewController which includes sideMenuViewController.Now I want to add loginViewController before tabViewController which is only one time login .currently.my app is working properly without loginViewController and following is the below code in AppDelegate.m class .

Now I want to include loginViewController before the tabViewController

please suggest me the necessary changes in my AppDelegate.m

AppDelegate.m

 (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
tabBarController = (UITabBarController *) self.window.rootViewController;
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];


        MFSideMenuContainerViewController *container = (MFSideMenuContainerViewController *)tabBarController.viewControllers [0];
        NSParameterAssert ([container isKindOfClass: [MFSideMenuContainerViewController class]]);
    //    UIViewController *historycontr=(UIViewController *)tabBarController.viewControllers[2];
    //    UIViewController *hist=[storyboard instantiateViewControllerWithIdentifier:@"historyController"];
        UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:@"navigationController"];
        UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:@"leftSideMenuViewController"];
        UIViewController *rightSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:@"rightSideMenuViewController"];

        [container setLeftMenuViewController:leftSideMenuViewController];
        [container setRightMenuViewController:rightSideMenuViewController];
        [container setCenterViewController:navigationController];



        return YES;
    }

Solution

  • Pull on a new UIViewController that will act as the login view controller onto the MainStoryboard. In the attribute inspector change the identifier to LoginViewController (or something appropriate)

    - (void)viewDidAppear:(BOOL)animated
    {
         [super viewDidAppear:animated];
    
          UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
          UIViewController *login = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
          [vc setModalPresentationStyle:UIModalPresentationFullScreen];
    
          [self presentModalViewController:login animated:YES];
    }
    

    after successful login just dismiss LoginViewController

    Check this Example