diff --git a/MMDrawerController/MMDrawerController.m b/MMDrawerController/MMDrawerController.m index 9d6fd507..f1265368 100644 --- a/MMDrawerController/MMDrawerController.m +++ b/MMDrawerController/MMDrawerController.m @@ -384,16 +384,28 @@ -(void)setCenterViewController:(UIViewController *)centerViewController animated if ([self.centerViewController isEqual:centerViewController]) { return; } + + if (_centerContainerView == nil) { + //This is related to Issue #152 (https://github.com/mutualmobile/MMDrawerController/issues/152) + // also fixed below in the getter for `childControllerContainerView`. Turns out we have + // two center container views getting added to the view during init, + // because the first request self.centerContainerView.bounds was kicking off a + // viewDidLoad, which caused us to be able to fall through this check twice. + // + //The fix is to grab the bounds, and then check again that the child container view has + //not been created. + CGRect centerFrame = self.childControllerContainerView.bounds; if(_centerContainerView == nil){ - _centerContainerView = [[MMDrawerCenterContainerView alloc] initWithFrame:self.childControllerContainerView.bounds]; + _centerContainerView = [[MMDrawerCenterContainerView alloc] initWithFrame:centerFrame]; [self.centerContainerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight]; [self.centerContainerView setBackgroundColor:[UIColor clearColor]]; [self.centerContainerView setOpenSide:self.openSide]; [self.centerContainerView setCenterInteractionMode:self.centerHiddenInteractionMode]; [self.childControllerContainerView addSubview:self.centerContainerView]; } - + } + UIViewController * oldCenterViewController = self.centerViewController; if(oldCenterViewController){ if(animated == NO){