实施“更多"tableView 中的按钮而无需再次重新加载整个 tableView [英] Implementing "More" button in tableView without reloading the whole tableView again

查看:23
本文介绍了实施“更多"tableView 中的按钮而无需再次重新加载整个 tableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 iOS 应用程序,其中我有一个 UITableView,其中包含来自 Web 服务的人员列表,并且底部有一个更多按钮.当用户点击更多时,它会调用一个服务,为列表提供一些新的人.现在我想在不重新加载整个 tableView 的情况下将这个列表与以前的 tableView 列表一起添加.我如何做到这一点.

I'm developing an iOS application in which i have a UITableView containing list of people coming from web-service and i have a more button on bottom. When user clicks on more it calls a service which provides some new people for the list. Now i want to add this list with the previous tableView list without reloading the whole tableView. how do i achieve this.

任何帮助将是非常可观的.我可以提供更多按钮的代码,我正在调用服务以从服务中获取数据.

Any help would be really appreciable. I can provide my code of more button where i'm calling the service to get the data from service.

推荐答案

UITableview 提供了多个用于操作内容的 API.你应该使用

UITableview provides several APIs for manipulating the content. You should use the

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

方法.表视图编程指南.

实际上,当单击按钮时,您会启动对名称列表的网络请求,完成后,您可以使用上述 API 将行添加到表中.

Practically, when the button is clicked, you start the network request for the list of names and when that finishes, you add the rows to the table with the above API.

注意:只要你只对表格视图做这个修改,你就不必使用beginUpdatesendUpdates 方法.如果同时进行多项更改(删除、添加、重新排序),则需要 beginUpdates/endUpdates.

Note: as long as you do only this modification to the table view, you don't have to use the beginUpdates, endUpdates methods. If there are multilple changes carried out at once (deletion, addition, reordering) then the beginUpdates/endUpdates is necessary.

这篇关于实施“更多"tableView 中的按钮而无需再次重新加载整个 tableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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