Some thoughts on this:
ONE
It looks like your containment methods are not being called properly. They should look like this for each viewController:
[self addChildViewController:controller];
[self.view addSubview:controller.view];
[controller didMoveToParentViewController:self];
The view should be added to the superview in between the addChild
and didMove
calls.
TWO
To my knowledge, there cannot be more than one presentation or dismissal occurring at a time. I.e. If you are trying to present (add) your child viewControllers at the same time as the modal is being dismissed, you will see an error in the console log and your "add" operation will not occur.
My recommendation would be to create a delegate protocol on the modal viewcontroller. And in the completion block of dismissViewControllerAnimated:completion:
, call your delegate method:
[self dismissViewControllerAnimated:YES completion:^{
if ([weakSelf.delegate respondsToSelector:@selector(settingsViewControllerDidDismiss:)])
{
[weakSelf.delegate settingsViewControllerDidDismiss:self];
}
}];
And in your rootViewController, you would begin adding its children inside of settingsViewControllerDidDismiss
or whatever you decide to call that method. The point is that the "add" operation begins AFTER the dismissal operation.
Hope this helps.