快速加载更多 UITableView [英] load more for UITableView in swift
问题描述
我在 swift 中为 iOS 和我的 Array 内容超过 500 个元素疯狂了 UITableView
.
I have mad UITableView
in swift for iOS and my Array content more then 500 elements.
我如何为 UITableView
制作页面,例如:
How can I make page for the UITableView
for Example:
一旦用户滚动到最新的 Cell
,应用就会加载更多 500 个元素等等.
once the user scroll for the latest Cell
the app load more fro the 500 elements and so on.
有什么帮助吗?
谢谢.
推荐答案
回答你的问题做了个小测试!这个问题的一个可能解决方案是创建另一个数组并将其添加到您要在表中显示的数据中,并将数据加载到您要加载的数据中!加载数据将DisplayCell forRowAtIndexPath
To answer your question made a small test! One possible solution to this problem is to make another array and add it to the data that you want to display in the table and load the data to the same that you want to load! Loading data will willDisplayCell forRowAtIndexPath
var allObjectArray: NSMutableArray = []
var elements: NSMutableArray = []
var currentPage = 0
var nextpage = 0
override func viewDidLoad() {
super.viewDidLoad()
for var i = 0; i <= 500; i++ {
allObjectArray.addObject(i)
}
elements.addObjectsFromArray(allObjectArray.subarrayWithRange(NSMakeRange(0, 20)))
}
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
println(indexPath.row)
nextpage = elements.count - 5
if indexPath.row == nextpage {
currentPage++
nextpage = elements.count - 5
elements.addObjectsFromArray(allObjectArray.subarrayWithRange(NSMakeRange(currentPage, 20)))
tableView.reloadData()
}
}
测试项目
https://drive.google.com/file/d/0B-CqajDlBoGHSE1OcjFoZWJxUTg/view?usp=sharing
这篇关于快速加载更多 UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!