我正在使用侧抽屉菜单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 我无法使它发挥作用。
答案 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;
}
}