UITabBarcontroller, UITableView and pushView
-
30-09-2019 - |
Question
I have a UITabBarController with a set of tabs. Some of them, when selected, show you a table. The cells of the table, if touched, bring the user to a detail screen of the object in the cell itself using a "pushViewController".
When I click to a different tab, and I am in the detail page, I see the new tab page. And this is fine. When I click back to the previous tab I would like to have shown again the table and not the detail page...
Is this possible?
Thanks!
Solution
It is possible. Code:
// Called when the user selected a tab. In iOS3+, called even when no change occurs.
- (void)tabBarController:(UITabBarController *)tabbarcontroller didSelectViewController:(UIViewController *)viewController
{
UINavigationController *nav = (UINavigationController *)viewController;
[nav popToRootViewControllerAnimated: NO];
}
Explanations:
- this is in your AppDelegate.
- Your AppDelegate is a UITabBarControllerDelegate.
- You set your UITabBarController's delegate (in InterfaceBuilder) to the AppDelegate.
- Your tabs must contain root controllers that are navigation controllers (must be, else your wouldn't be able to 'push' details).
OTHER TIPS
See the UITabBarControllerDelegate
protocol to set up which controller will be notified when tabs are switched then just pop the detail controller using that.
BTW, you can also do most of this navigation controller setup in interface builder like this: