Sasha Grievus
Sasha Grievus

Reputation: 2686

How to correctly pop views in ios app?

I have this flow: UITableView foo -> detail UIView bar containing another UITableView foo_1 -> detail UIView bar_1

The first UITableView foo contains a list of thing and leads to a detail UIView bar that contains another UITableView foo_1 that leads to another UIView bar_1 containing more details. Now, i have several buttons on the main app tabbar, and i can change view using it. When i tap a button leading to another view and then tap the button supposed to lead back to my UITableView foo, i am presented with foo, bar or bar_1, depending on which view i was, the last time i used the flow i described, but i want to go back to foo every single time i tap the corresponding button on the tabbar.

I supposed the right way to do this was by:

-(void) viewWillDisappear:(BOOL)animated{
    [self.navigationController popToRootViewControllerAnimated:NO];
}

but i am not sure where to use this code... I tried putting it in bar_1 but it results in a "nested pop animation can result in corrupted navigation bar Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.". The result is a navigation bar getting mad and showing itself empty... So what is the correct way to go back in a similar situation?

Upvotes: 0

Views: 90

Answers (1)

Daniel Rinser
Daniel Rinser

Reputation: 8855

The most straight-forward way would be to have a delegate for your UITabBarController and put your code inside the tabBarController:didSelectViewController: method, which gets called every time the active tab is switched. Of course, you should check if it's the right view controller to not pop to the root one every tab switch.

Upvotes: 1

Related Questions