点击选项卡栏滚动到UITableViewController的顶部 [英] Tap tab bar to scroll to top of UITableViewController

查看:66
本文介绍了点击选项卡栏滚动到UITableViewController的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击当前导航控制器的标签栏图标已经使用户返回到根视图,但是如果将它们向下滚动,如果再次点击它,我希望它滚动到顶部(与点击状态相同的效果)酒吧).我该怎么做?

Tapping the tab bar icon for the current navigation controller already returns the user to the root view, but if they are scrolled way down, if they tap it again I want it to scroll to the top (same effect as tapping the status bar). How would I do this?

一个很好的例子是Instagram的供稿,向下滚动,然后点击选项卡栏中的主页图标以滚动回到顶部.

A good example is Instagram's feed, scroll down then tap the home icon in the tab bar to scroll back to top.

滚动到顶部很容易,但是将其连接到选项卡栏控制器正是我所坚持的.

The scrolling back to the top is easy, but connecting it to the tab bar controller is what I'm stuck on.

推荐答案

实施UITabBarControllerDelegate方法tabBarController:didSelectViewController:,以便在用户选择选项卡时得到通知.即使再次选择了相同的选项卡按钮,也再次调用该方法.

Implement the UITabBarControllerDelegate method tabBarController:didSelectViewController: to be notified when the user selects a tab. This method is also called when the same tab button is tapped again, even if that tab is already selected.

实现此delegate的好地方可能是您的AppDelegate.或逻辑上拥有"标签栏控制器的对象.

A good place to implement this delegate would probably be your AppDelegate. Or the object that logically "owns" the tab bar controller.

我将声明并实现一个可以在视图控制器上调用以滚动UICollectionView的方法.

I would declare and implement a method that can be called on your view controllers to scroll the UICollectionView.

- (void)tabBarController:(UITabBarController *)tabBarController 
 didSelectViewController:(UIViewController *)viewController
{
    static UIViewController *previousController = nil;
    if (previousController == viewController) {
        // the same tab was tapped a second time
        if ([viewController respondsToSelector:@selector(scrollToTop)]) {
            [viewController scrollToTop];
        }
    }
    previousController = viewController;
}

这篇关于点击选项卡栏滚动到UITableViewController的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆