在tableView中实现“更多”button,而无需重新加载整个tableView

我正在开发一个iOS应用程序,其中我有一个UITableView包含来自Web服务的人员列表,我有一个更底部的button。 当用户点击更多时,它会调用一个为列表提供一些新用户的服务。 现在我想添加这个列表与以前的tableView列表,而无需重新加载整个tableView。 我如何做到这一点。

在这里输入图像说明 任何帮助将是非常可观的。 我可以提供更多button的代码,我打电话给服务来获取服务的数据。

UITableview提供了几个API来操纵内容。 你应该使用

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation: (UITableViewRowAnimation)animation; 

方法。 Table View Programming Guide中描述了如何应用它们的方式。

实际上,单击button时,将启动networking请求列表中的名称,并在完成后,使用上述API将行添加到表中。

注意:只要你只对表视图进行了这种修改,就不必使用beginUpdatesendUpdates方法。 如果一次执行多个更改(删除,添加,重新sorting),则beginUpdates / endUpdates是必要的。

看看UITableView的 – beginUpdates; 和- endUpdates方法。

在调用这些函数之间,您必须将行插入到表视图中。 如果你使用的是UITableView的 – insertRowsAtIndexPaths:withRowAnimation:方法,你甚至可以跳过begin和endUpdates

在调用insertRowsAtIndexPaths:withRowAnimation:之前,确保将新对象插入到数据源对象insertRowsAtIndexPaths:withRowAnimation:

如果你不想重新加载表格,那至less,你必须打电话

 insertRowsAtIndexPaths: withRowAnimation: 

除了你不能在你的表格视图中显示新添加的数据。

根据我的经验, It is not possible重新加载/显示新的名称到表视图是不可能的。

但是你可以完成你的任务如下:

你可以设置arraCount(one varaible) for namesArray count 。 在调用webservice之后,你可以increment arrayCount varaiable and reload the table view ,这将在表中显示新增的名字。

希望这会有所帮助。