From 1435c0b3e90693936102f87b3aa4a00746dfdc0b Mon Sep 17 00:00:00 2001 From: ShoaibGhaffar Date: Wed, 27 May 2015 20:55:46 +0500 Subject: [PATCH] Fixed Crashing Fixed Crashing when setCenterViewController = nil to free memory --- MMDrawerController/MMDrawerController.m | 30 ++++++++++++++----------- 1 file changed, 17 insertions(+), 13 deletions(-) mode change 100644 => 100755 MMDrawerController/MMDrawerController.m diff --git a/MMDrawerController/MMDrawerController.m b/MMDrawerController/MMDrawerController.m old mode 100644 new mode 100755 index 4aec238b..baddf95b --- a/MMDrawerController/MMDrawerController.m +++ b/MMDrawerController/MMDrawerController.m @@ -430,20 +430,24 @@ -(void)setCenterViewController:(UIViewController *)centerViewController animated _centerViewController = centerViewController; - [self addChildViewController:self.centerViewController]; - [self.centerViewController.view setFrame:self.childControllerContainerView.bounds]; - [self.centerContainerView addSubview:self.centerViewController.view]; - [self.childControllerContainerView bringSubviewToFront:self.centerContainerView]; - [self.centerViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; - [self updateShadowForCenterView]; - - if(animated == NO){ - // If drawer is offscreen, then viewWillAppear: will take care of this - if(self.view.window) { - [self.centerViewController beginAppearanceTransition:YES animated:NO]; - [self.centerViewController endAppearanceTransition]; + //if centerViewController is nil, It should not call 'addChildViewController:' + if (_centerViewController) + { + [self addChildViewController:self.centerViewController]; + [self.centerViewController.view setFrame:self.childControllerContainerView.bounds]; + [self.centerContainerView addSubview:self.centerViewController.view]; + [self.childControllerContainerView bringSubviewToFront:self.centerContainerView]; + [self.centerViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; + [self updateShadowForCenterView]; + + if(animated == NO){ + // If drawer is offscreen, then viewWillAppear: will take care of this + if(self.view.window) { + [self.centerViewController beginAppearanceTransition:YES animated:NO]; + [self.centerViewController endAppearanceTransition]; + } + [self.centerViewController didMoveToParentViewController:self]; } - [self.centerViewController didMoveToParentViewController:self]; } }