Search code examples
iosuitableviewuitabbarcontrolleruitabbaruitabview

iOS tabbed application with table view, how to reset table view tab? Beginner.


I have a tabbed application with 3 tabs

The first tab is a table view The second and third tabs are single page views

When a user clicks on a table cell in view one a new view is pushed on with a back button to the table cell.

Now lets say they click tab 2, then back to tab 1. The new view that was pushed on tab 1 is still visible. What I would like is to have the table view "reset" when they navigate away from it with another tab so that when they return they are presented with the table view instead of the new view that was pushed on .


Solution

  • I agree with ElJay comment, but to answer the question use UITabBarControllerDelegate

    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
    

    when a new tab is selected see if the current one is tab 1 selectedIndex property of tabBarController and if so popToRootViewController: