0
votes

I have UITabBarController which each item has NavigationController and each NavigationController has a TableViewController as root view controller.

The problem is tapping on each tab bar item doesn't make table view to scroll to top.

What could be problem and how can I solve it?

2
Did you write [yourtableview setScrollsToTop:YES]; on tapping method of tab bar ?NiravPatel
@NiravPatel Yes I did!aakpro
In this case, you can set tableview content offset to zero.NiravPatel

2 Answers

1
votes

Well the answer is this:

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    MasterTableViewController * theViewController;
    if (tabBarController.selectedViewController == viewController)
    {
        if ([viewController isKindOfClass:[UINavigationController class]])
        {
            UINavigationController * nav = (UINavigationController *)viewController;
            theViewController = (MasterTableViewController *)nav.topViewController;
        }
        else
        {
            theViewController = self;
        }
        if ([theViewController respondsToSelector:@selector(navigationBarDoubleTap:)])
        {
            [theViewController navigationBarDoubleTap:nil];
        }
    }
    return YES;
}
-2
votes

Check if your tab items is double tapped or not. If yes, then scrollsToTop like below:-

Add below code:-

-(void)viewWillAppear:(BOOL)animated{
    [tableView scrollsToTop];
}