如何添加“加载更多”滚动到表格底部时的页面 [英] How to add "Load more" page when scrolling to bottom of table

查看:219
本文介绍了如何添加“加载更多”滚动到表格底部时的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出当处理UItableView的底部时处理分页或加载更多...的最佳方法。
我正在从Web服务加载此数据,这非常灵活,为我提供了pagesize和page参数。 Pagesize定义每次返回的结果数,而page参数定义搜索结果组,例如:

I'm trying to figure out the best way to handle paging or a "Load More..." when scoll to bottom in a UItableView. I'm loading this data from a web service, that's pretty flexible, giving me a pagesize and page parameter. Pagesize defines the number of results pulled back each time, whereas the page parameter defines groups of search results, for example:

page = 1(返回结果1-10)。

page=1 (returns results 1-10).

page = 2(返回结果11-20)

page=2 (returns results 11-20)

每次,当向下滚动到底部时,我请求服务器1次,服务器将给我1页(1、2、3、4 ....)和结果。
i试图像这样加载

Each time, when scroll down to bottom, i request to server 1 time and server will give me 1 page(1, 2, 3, 4 ....) and result. i tried to load like this

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat height = scrollView.frame.size.height;

    CGFloat contentYoffset = scrollView.contentOffset.y;

    CGFloat distanceFromBottom = scrollView.contentSize.height - contentYoffset;
    if(distanceFromBottom < height)
    {
        //to do something
        [self.viewController getPics];
    }

}

我不确定解决这个问题。任何帮助都会很棒。

I'm not really sure how to tackle this. Any help would be great. Thanks in advance.

推荐答案

以下代码段将检测用户是否滚动到滚动视图的底部。

您可以调用该方法在if语句的主体中从服务器(异步)获取更多数据。

The following snippet will detect if the user scrolled to the bottom of the scroll view.
You can call the method to get more data from the server (asynchronous) in the body of if statement.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if ([scrollView contentOffset].y == [scrollView contentSize].height - [scrollView frame].size.height) {
        // The user did scroll to the bottom of the scroll view
    }
}

这篇关于如何添加“加载更多”滚动到表格底部时的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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