views:

497

answers:

2

UITabBarController with UINavigationController "more" tab issue

There is a problem with using UINavigationController in UITabBarController. I have a TabBar  with 6 items. Of course, a standart item "more" appears, and there are two UINavigationControllers that didn't fit in a TabBar. The core of the problem is: when I'm working with visible items (a first four), UIViewController can be pushed  in an UINavigationController:

[self.navigationController pushViewController:userDataViewController animated:YES];

If you call on in "more" and rearrange items in such way, that a visible UINavigationController gets into "more", when calling on it userDataViewController appears.  This  userDataViewController is the last, which has got in a stack and a Back button leads back to "more", but not to the controllers, that were before a userDataViewController appeared.

I understand that in fact a selector pushViewController is called from "more", and it pushes my UINavigationController in a stack, and it's not good. Maybe, someone has faced such problem and could help me to solve it?

Thank you forward.

+1  A: 

A possible solution is to force your UINavigationController to return to its root view controller just before a user saves changes of the tab bar configuration. To do that, implement the following method in your tab bar controller's delegate:

- (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed {
if (changed) {
    NSLog (@"User has rearranged tab bar items");

    for (UIViewController *controller in tabBarController.viewControllers) {
        if ([controller isKindOfClass:[UINavigationController class]]) {
            [((UINavigationController *)controller) popToRootViewControllerAnimated:NO];
        }
    }
}

}

Aliaksei
Stumbled on this bug today. This fixed it for me. thanks alot Aliaksei, I did had to add `tabBarController.delegate = self;` before it worked, so watch for that.
Yarek T
A: 
sugar