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

iOS

Ribbit app tabbar reset view

How to a make sure that every time I press the tab bar I start with first view and for example not edit friends view instead of friends? Now it opens last active view

Peace and Love

2 Answers

I think you are going to have to use a UITabBarController Delegate method such astabBarController:didSelectViewController: to handle that. you would need to implement that delegate method

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  //get the current view controller (the one you want to reset back to the root view)
  UIViewController *viewController = tabBarController.selectedViewController;
  //pop to root view controller assuming your view controller has a navigationController 
 [viewController.navigationController popToRootViewControllerAnimated:NO];
}

Thank you Stone Preston

I tried like this and did not work. I added in the bottom of the m file. Should I change something more?

´´´

  • (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { //get the current view controller (the one you want to reset back to the root view) UIViewController *ProfileEditviewController = tabBarController.selectedViewController; //pop to root view controller assuming your view controller has a navigationController [EditviewController.navigationController popToRootViewControllerAnimated:NO]; }

´´´

Any other ideas anyone?