From 4c74a5b10536d06ee519692473644d7a40c5521a Mon Sep 17 00:00:00 2001 From: Aryan Gh Date: Sat, 27 Apr 2013 10:18:35 -0700 Subject: [PATCH] - Avoid switching to ViewController if it's the same class type as the current view controller, and instead just close the slide menu - this option is configurable by setting a bool called avoidSwitchingToSameClassViewController --- SlideMenu/Source/SlideNavigationController.h | 1 + SlideMenu/Source/SlideNavigationController.m | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/SlideMenu/Source/SlideNavigationController.h b/SlideMenu/Source/SlideNavigationController.h index 0d66769..ef8db6a 100644 --- a/SlideMenu/Source/SlideNavigationController.h +++ b/SlideMenu/Source/SlideNavigationController.h @@ -22,6 +22,7 @@ typedef enum{ @interface SlideNavigationController : UINavigationController +@property (nonatomic, assign) BOOL avoidSwitchingToSameClassViewController; @property (nonatomic, strong) UIViewController *righMenu; @property (nonatomic, strong) UIViewController *leftMenu; @property (nonatomic, strong) UIBarButtonItem *leftbarButtonItem; diff --git a/SlideMenu/Source/SlideNavigationController.m b/SlideMenu/Source/SlideNavigationController.m index feee0dc..078ea4c 100644 --- a/SlideMenu/Source/SlideNavigationController.m +++ b/SlideMenu/Source/SlideNavigationController.m @@ -64,6 +64,7 @@ static SlideNavigationController *singletonInstance; - (void)setup { + self.avoidSwitchingToSameClassViewController = YES; singletonInstance = self; self.delegate = self; @@ -81,6 +82,12 @@ static SlideNavigationController *singletonInstance; - (void)switchViewController:(UIViewController *)viewController withCompletion:(void (^)())completion { + if (self.avoidSwitchingToSameClassViewController && [self.topViewController isKindOfClass:viewController.class]) + { + [self closeMenuWithCompletion:completion]; + return; + } + __block CGRect rect = self.view.frame; if ([self isMenuOpen])