iOS - 用户到达滚动视图底部时加载项目
我目前使用CloudKit作为我的后端,到目前为止,我一直在享受它。iOS - 用户到达滚动视图底部时加载项目
我有一个查询发生,检索数据填充表视图。由于我不知道它可能有的项目数,我正在过滤查询X个项目(比如说15)。
我的目标是,当用户滚动到表格视图底部(最后查询的项目)生病查询后端继续填充表格视图。
我已经搜索,但无法找到这样做的CloudKit代码。
有人可以给我一个提示如何做到这一点?
谢谢大家给予的帮助。 最好,伊万。
关于IOS我认为你必须使用UITableViewController或者只是使用UITableView。
添加一个UIActivityIndicatorView(即微调)到你的UITableViewController。出口连接到代码:
@IBOutlet weak var spinner: UIActivityIndicatorView!
一个属性添加到您的UITableViewController跟踪过你现在正在加载更多数据,让你不要试图做两次:
var loadingData = false
启动微调器动画,然后调用refreshRes():
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if !loadingData && indexPath.row == refreshPage - 1 {
spinner.startAnimating()
loadingData = true
refreshRes()
}
让refreshRes()在后台线程上运行。这将使您的桌子仍然可以自由移动。动画微调将告诉用户更多的数据即将到来。一旦您的查询返回,更新主线程上的表数据。
func refreshRes() {
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)) {
// this runs on the background queue
// here the query starts to add new 15 rows of data to arrays
dispatch_async(dispatch_get_main_queue()) {
// this runs on the main queue
self.refreshPage += 15
self.tableView.reloadData()
self.spinner.stopAnimating()
self.loadingData = false
}
}
之后,它的依赖,你必须做出让别人15个DATAS
非常感谢。 –
@G Clovs我想知道你如何使用refreshPage属性?我需要一个特定的代表吗? –
我明白了。 refreshPage是检索的当前项目跟踪器 –
为什么要注意使用'uitableview'请求服务器的结果?你可以用键搜索并得到许多结果:“UITableView加载更多” – anhtu
我错过了写的问题我没有使用滚动视图我正在使用tableView –