滚动到底部时 UITableView 加载更多 [英] UITableView load more when scrolling to bottom

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

问题描述

我想在用户滚动到表格底部时加载更多数据并创建其他单元格.我正在使用 JSON 数据和 MySql.

I would like to load more data and create additional cells when the user scrolls to the bottom of the table. I'm using JSON data and MySql.

func dataJsonFromURL(url:String)->NSArray
{
    if let data = NSData(contentsOfURL: NSURL(string: url)!) {
        return ((try! NSJSONSerialization.JSONObjectWithData(data, options: [])) as! NSArray)
    }
    else{
        return data
    }
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("NCell", forIndexPath: indexPath) as! TableViewCell22

    cell.backgroundColor = UIColor .clearColor()

    let mindata = (data[indexPath.row] as! NSDictionary)
}

推荐答案

你得用这个方法

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
            let lastElement = dataSource.count - 1
            if indexPath.row == lastElement {
                // handle your logic here to get more items, add it to dataSource and reload tableview
                }    
        }

这篇关于滚动到底部时 UITableView 加载更多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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