迅速为UITableView加载更多 [英] load more for UITableView in swift

查看:59
本文介绍了迅速为UITableView加载更多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很快就为iOS迷上了UITableView,我的数组内容超过了500个元素.

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.

有什么帮助吗?

谢谢.

推荐答案

为回答您的问题进行了一次小测试!解决此问题的一种可能方法是制作另一个数组,并将其添加到要在表中显示的数据中,然后将数据加载到要加载的数据中!加载数据将willDisplayCell 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屋!

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