Carl Carl - 1 year ago 82
iOS Question

Popping all View Controllers on Tab Bar App

I have a tab bar app with navigation controllers on 4 out of the 5 tabs on the app. I have a 'reset app' function within my app which clears all data etc... and I would also like that to pop all of the view controllers back to their top view. I know how to pop to root using popToRootViewControllerAnimated for a single nav controller but is it possible to pop all of the view controllers on each tab?

Answer Source

You need to enumerate through viewControllers array of tabBarController & pop to root view controller if controller in array is UINavigationController like-

for(UIViewController *viewController in tabBarController.viewControllers)
    if([viewController isKindOfClass:[UINavigationController class]])
       [(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download