2011-05-28 58 views
12

嘿, 任何人都可以指导我通过这个我有大约15个表中的条目我想另一个15在上一个UITableViewCell中获得更多的负载。任何人都可以帮我吗?在uitableviewcell中做一个“加载更多”按钮?

+2

[“Load More”in UITableView](http://stackoverflow.com/questions/4410257/)或[如何实现“Load 25 More”](http://stackoverflow.com/questions/) 2801069 /)或[邮件应用程序加载更多的消息](http://stackoverflow.com/questions/4396464/)或[在iPhone中加载更多记录](http://stackoverflow.com/questions/4965919/)或[Add加载更多选项到表[视图](http://stackoverflow.com/questions/5898399/)其中[others](http://stackoverflow.com/search?q=iphone+load+more) – 2011-05-28 07:32:41

回答

19

显示额外的行中的tableview,在

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return dataRows+1; 
    } 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

     //after setting tableviewcell 

     if(indexPath.row==dataRows){ 

     [email protected]"Load More Rows"; 
     } 
    } 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

    if(indexPath.row==dataRows){ 
    //there you can write code to get next rows 
    } 
} 

您需要根据显示的行更新numberOfRows变量。

编辑:获取额外的条目后,您可以使用以下方法将它们添加到现有的条目数组中。您的原始数组应该是NSMutableArray以使用此方法。

[originalEntriesArray addObjectsFromArray:extraEntriesArray];

+0

@SriPriya,添加此line'numberOfRows = [yourEntriesArray count] + 1;'使之更加清晰。 – EmptyStack 2011-05-28 05:48:28

+0

@Simon:你好,我更新了代码 – SriPriya 2011-05-28 05:53:23

+0

@SriPriya,嗯:) – EmptyStack 2011-05-28 05:56:32

1

希望这有助于

我花了一个可变数组和一个整型变量,并设置数组整型变量

 
arr = [[NSMutableArray alloc]initWithObjects:@"Radix",@"Riki", nil]; 
dataRows = [arr count]; 

,然后我设定数量的总数根据表格的数据源方法中的整数变量在行中的行数

 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    // Return the number of rows in the section. 
    return dataRows+1; 
} 

因为你想在最后一个额外的单元格。

现在就设置表单元的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 静态的NSString * CellIdentifier = @ “小区” 的文本;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Configure the cell... 

//setting the text of the cell as per Mutable array 
if (indexPath.row < [arr count]) { 

    cell.textLabel.text = [arr objectAtIndex:indexPath.row]; 
} 

//setting the text of the extra cell 

if (indexPath.row == dataRows) { 
    cell.textLabel.text = @"more cells"; 
}  
return cell; 

}

现在

的多个细胞的细胞的命中你想要额外的细胞右所以只需添加

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

方法里面的代码,意味着你必须做这样的事情

 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.row == dataRows) 
    { 
     //code for exra cells please 
    } 
} 

运行您的应用程序来检查此代码。

4

下载它,我写的东西可能会有所帮助:https://github.com/nmondollot/NMPaginator

它封装了分页,并与几乎使用页面和per_page参数的任何web服务工作。它还具有一个UITableView,可在您向下滚动时自动获取下一个结果。