开发者

UITabbarcontroller with nested pages - cannot get tab bar control to show root

开发者 https://www.devze.com 2023-04-06 15:47 出处:网络
I have used UITabbar control to navigate to the top level pages of my app.Each top level page navigates to 5 other pages using command buttons to drill deeper.When the user selects the next tabbar ite

I have used UITabbar control to navigate to the top level pages of my app. Each top level page navigates to 5 other pages using command buttons to drill deeper. When the user selects the next tabbar item, instead of navigating to the root, they end up on the page they were last reading in the hierarchy. I am using XCode 4 and Tab Bars have been created using IB.

How can I change this behavior so that the tab bar button always navigates to the top level page? Your help would be very much appreciated since I have spent many days trying t开发者_开发问答o resolve this issue.


I believe this will work if your tabs have UINavigationController at their root

//somewhere in the initialization process
tabBarController.delegate = self

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    UINavigationController *navController = (UINavigationController *)viewController;
    if([navController.viewControllers count]>0)
        [navController popToRootViewControllerAnimated:NO];
}


I have implemented UITabBar with each button loading a separate view controller and each of those view controllers having a navigation controller as a drill-down interface. When each button on the tab bar is clicked, the UIViewController is loaded and it is responsible for handling the drill down.

This sounds like what you want to do. Since I'm not sure what you mean by "page", I don't know how you are implementing the change that happens when a button is tapped on the tab bar. It sounds like you have one UIViewController and that's not quite how the UITabBar was designed to function. I could be wrong, so I think a little more explanation is needed.

If you are implementing with multiple UIViewControllers, You may want to think about whether a user is going to want to remain buried in the drill down even on changing tabs. Not sure what you App does, but this may be desired behavior.

0

精彩评论

暂无评论...
验证码 换一张
取 消