Abh*_*gal 11 iphone uitableview
在我的应用程序中,我从Web服务获取数据,我必须在UITableView中显示它.但这里的条件是我最初只需显示10条记录,然后一旦用户向下滚动我必须加载更多记录.我尝试搜索它但没有得到任何有用的答案.我同意我会用 -
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
Run Code Online (Sandbox Code Playgroud)
显示值,但我如何从服务中获取10条记录,然后根据滚动获取其他记录.请提供一些指示或示例代码.
谢谢
Abh*_*gal 11
如果有人需要它,我能够以这种方式解决我的问题.首先,您需要以这种方式配置服务器,以便它应该根据TableView中可见的行一次返回10个数据.这是被调用的tableView委托,并返回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
}
}
}
Run Code Online (Sandbox Code Playgroud)
savedscrollPosition变量将变量存储为要在加载数据后滚动表视图的点.
你应该阅读延迟加载.该代码可在Apple的网站上找到.在这里下载
http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
检查代码
- (void)loadImagesForOnscreenRows
Run Code Online (Sandbox Code Playgroud)
方法.
它使用您需要的相同方法.它获取表视图的当前滚动位置,并在此基础上,它将获取屏幕上显示的单元格及其indexPath.在此基础上,您将能够显示屏幕中显示的那些单元格.
要显示10行,需要进行简单的计算.
| 归档时间: |
|
| 查看次数: |
19089 次 |
| 最近记录: |