如何使用自定义后UI按钮POP视图控制器?

时间:2016-05-05 06:32:21

标签: ios objective-c mmdrawercontroller

我正在使用侧抽屉菜单https://github.com/mutualmobile/MMDrawerController 我无法使用自定义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];

}

我也试过这个https://github.com/mutualmobile/MMDrawerController/issues/195 我无法使它发挥作用。

2 个答案:

答案 0 :(得分:0)

您可以考虑设置一个全局变量(例如,在单例或数据库中)使用viewDidDissapear来自哪个ViewController:

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

从那里你可以知道你来自哪里(例如IBAction):

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

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

我将此用于具有自定义分段和编程导航的应用程序。

答案 1 :(得分:0)

请尝试这个。可能对你有帮助

       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;
                }
            }