So I have a viewController A that presents a modal viewController B.
Then B presents a viewController C.
What I’m trying to do is to dismiss viewController B since I dont need it anymore. Is there a simple way to dismiss B and keep C on the screen as a child of A maybe?
Obviously, as many have said, this in a textbook world would/should be a delegate situation. Where
ApresentsBandBpresentsC. Then whenCis done it tellsBwhich dismissesCand thenBtellsAto dismissB.I would argue that you are essentially creating a set of modally presented view controllers that amounts to a navigation stack. I would likely implement it as such. Where
Awould be the root view controller.Awould then pushBonto the stack andBwould pushConto the stack. WhenCwas done it could simplypopToRootViewControllerAnimated:orpopToViewController:A animated:YESifAwas not the rootViewController.Also removing
Bout from underneath ofCseems problematic. But it doesn’t sound like that is set in stone based on your comment:That would at least enable a fairly clean delegate setup.
Still it seems like you basically know that when the user is done with
Cthey would never needBagain. If this is the case you can blindly dismiss two or more view controllers at once. And the code for two at a time is fairly simple. (assuming iOS version > 5.0)Please note that I said blindly! This code is not forgiving and makes assumptions. For example most obviously that the view controller does in fact have a
presentingViewControllerand that that view controller has apresentingViewController. If either of these criteria is not met then this code will do nothing. This could easily happen if you at any point restructure your app.So again, if you choose to use this line of code, use it very carefully. And please do consider using a
UINavigationControllerfor this view hierarchy, or at least delegation.