I use the following static utility method to model popToRootViewController for the modal stack:
+ (void)popModalsToRootFrom:(UIViewController*)aVc {
if(aVc.parentViewController == nil) {
return;
}
else {
[Util popModalsToRootFrom:aVc.parentViewController];
[aVc.parentViewController dismissModalViewControllerAnimated:NO];
}
}
You use it as follows:
[Util popModalsToRootFrom:aViewController]
If you want something more advanced, you can do this:
+ (void)popModalsFrom:(UIViewController*)aVc popCount:(int)count {
if(aVc.parentViewController == nil || count == 0) {
return;
}
else {
[Util popModalsFrom:aVc.parentViewController popCount:count-1];
[aVc.parentViewController dismissModalViewControllerAnimated:NO];
}
}
Then pass in the number of modals you need to place, or just -1 to completely fill the root.
source
share