Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Reset tab bar to default view when pressed

I want to reset the tabbar every time I press the tab bar. Now it opens in last active view.

I tried something like this. But it dosen't work?

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)SettingsViewController{ //get the current view controller (the one you want to reset back to the root view)

    UIViewController *ProfileViewController = tabBarController.selectedViewController; //pop to root view controller assuming your view controller has a navigationController

    [ProfileViewController.navigationController popToRootViewControllerAnimated:NO]; }

3 Answers

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Sorry, I don't understand the desired behavior. Where on the tab bar is the user supposed to touch? And when that happens, do you want to pop to the root view controller of the current tab's navigation controller, or cause a specific tab to be shown?

I changed the place of the log out button in the ribbit app to a cell. That cell is placed in a view called settings. Settings is placed in one of my tabs called profile. So when I log out a user and log in again instead of going to profile the user ends up in settings. So basically when I log out a user from my app I want the app to dismiss the settings view controller before logging out. So when the user logs in again and press the profile tab bar he actually shows up in profile instead of a under category called settings where I have my log out button. Thanks!

Ben Jakuben
Ben Jakuben
Treehouse Teacher

When the user successfully logs in, perhaps you could set the index of the tab bar controller using setSelectedIndex. Then you could try the popToRootViewControllerAnimated method to force it back to the Profile view controller.