diff --git a/MMDrawerController/UIViewController+MMDrawerController.m b/MMDrawerController/UIViewController+MMDrawerController.m index 7ffc0542..d2ffe3b8 100644 --- a/MMDrawerController/UIViewController+MMDrawerController.m +++ b/MMDrawerController/UIViewController+MMDrawerController.m @@ -25,16 +25,14 @@ @implementation UIViewController (MMDrawerController) -(MMDrawerController*)mm_drawerController{ - if([self.parentViewController isKindOfClass:[MMDrawerController class]]){ - return (MMDrawerController*)self.parentViewController; - } - else if([self.parentViewController isKindOfClass:[UINavigationController class]] && - [self.parentViewController.parentViewController isKindOfClass:[MMDrawerController class]]){ - return (MMDrawerController*)[self.parentViewController parentViewController]; - } - else{ - return nil; + UIViewController *parentViewController = self.parentViewController; + while (parentViewController != nil) { + if([parentViewController isKindOfClass:[MMDrawerController class]]){ + return (MMDrawerController *)parentViewController; + } + parentViewController = parentViewController.parentViewController; } + return nil; } -(CGRect)mm_visibleDrawerFrame{