加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 当滚动到底部时,UITableView加载更多

发布时间:2020-12-14 05:50:09 所属栏目:百科 来源:网络整理
导读:我想在用户滚动到表格底部时加载更多数据并创建其他单元格。我正在使用JSON数据和MySql。 func dataJsonFromURL(url:String)-NSArray{ if let data = NSData(contentsOfURL: NSURL(string: url)!) { return ((try! NSJSONSerialization.JSONObjectWithData(d
我想在用户滚动到表格底部时加载更多数据并创建其他单元格。我正在使用JSON数据和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
                }    
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读