0

I am using side drawer menu https://github.com/mutualmobile/MMDrawerController I cannot come to back with custom UIButton.

- (IBAction)doBackAction:(id)sender {
       NSArray *viewControllers=self.navigationController.viewControllers;
    for (UIViewController *viewController in viewControllers) {
         NSLog(@"%@",NSStringFromClass([viewController class]));
        UINavigationController *obj=(UINavigationController *)[self.mm_drawerController centerViewController];

    }
    UINavigationController *nav =
    (UINavigationController *)self.mm_drawerController.centerViewController;
    [nav popToRootViewControllerAnimated:NO];
    [self.navigationController popViewControllerAnimated:YES];
    [self.mm_drawerController closeDrawerAnimated:YES completion:nil];

}

i have tried this also https://github.com/mutualmobile/MMDrawerController/issues/195 I cannot make it work.

karthikeyan
  • 3,821
  • 3
  • 22
  • 45

2 Answers2

0

You might consider setting a global variable (e.a. on a singleton or in a database) which ViewController you came from with viewDidDissapear:

- (void)viewDidDissapear {
    Singleton.lastViewController = [self class];
}

From there you can do this to know where you came from (e.a. an IBAction):

// Set your global variable: `NSString` Singleton.lastViewController

[self presentViewController:[[UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil] instantiateViewControllerWithIdentifier:Singleton.lastViewController] animated:YES completion:nil];

I use this for apps that have custom segues and programmed navigation.

0

Please try this one. May be its help to you

       for (UIViewController *controller in self.navigationController.viewControllers)
            {


                if ([controller isKindOfClass:[CartVC class]])
                {
                    //Do not forget to import CompareCarsVC.h
                    //                CATransition *transition = [CATransition animation];
                    //                transition.duration = 0.5;
                    //                transition.type = kCATransitionFade;
                    //
                    //                [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];

                    [self.navigationController popToViewController:controller
                                                          animated:NO];
                    break;
                }
            }
Vijay Kachhadiya
  • 366
  • 2
  • 11