UItableView在滚动时加载数据 [英] UItableView load data on scroll

查看:144
本文介绍了UItableView在滚动时加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我从Web服务获取数据,我必须在UITableView中显示它。
但这里的条件是我最初只需显示10条记录,然后一旦用户向下滚动我必须加载更多记录。我尝试搜索它但没有得到任何有用的答案。
我同意我将使用 -

In my app I am getting the data from the web-service and I have to display it in UITableView. But the condition here is I have to display only 10 records initially,then once the user scroll down I have to load more records.I tried searching it but didn't get any useful answer. I agree that I will use -

(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

显示值,但我将如何获取来自服务的10条记录,然后基于滚动的其他记录。
请提供一些指示或示例代码。

to display the value,but how will I fetch only 10 records from the service and then other record based on scroll. Please provide some pointers or sample code.

谢谢

推荐答案

如果有人需要它,我能够以这种方式解决我的问题。
首先,您需要以这种方式配置服务器,以便它应该根据TableView中可见的行一次返回10个数据。
这是被调用的tableView委托并返回tableView中的可见单元格

In case if some one need it,i was able to solve my problem this way. First thing is you need the server configuration in such a way so that it should return 10 data at a time based on the row which is visible in TableView. This is the tableView delegate which get called and returns the visible cells in tableView

 -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        int lastRow=[nameArray count]-1;
        if(([indexPath row] == lastRow)&&(lastRow<[categoryArray count]))  
        {

            if(tableView==m_pDetailsTableView)    {
                savedScrollPosition=lastRow;
                startCellValue=[NSString stringWithFormat:@"%d",0];
                endCellValue=[NSString stringWithFormat:@"%d",[nameArray count]+10];
                [self connectToServer]; //Method to request to server to get more data
            }
        }
    }

savedscrollPosition变量将变量存储为您希望在加载数据后滚动表视图的点。

savedscrollPosition variable stores the variable as a point where you want to scroll the table view after load of data.

这篇关于UItableView在滚动时加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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