简体   繁体   English

双击UITabBarItem不会将UITableView滚动到顶部

[英]Double tap on UITabBarItem doesn't scroll UITableView to top

I have UITabBarController which each item has NavigationController and each NavigationController has a TableViewController as root view controller. 我有UITabBarController,每个项目都有NavigationController,每个NavigationController有一个TableViewController作为根视图控制器。

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? 可能是什么问题,我该如何解决?

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;
}

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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM