在swift2中看不到cellForNextPageAtIndexPath [英] cellForNextPageAtIndexPath not visible in swift2

查看:92
本文介绍了在swift2中看不到cellForNextPageAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Parse中实现带有部分和分页的PFQueryTableViewController.因为我使用的是节,所以我需要自己设置加载更多"单元格.但是,看来我无法访问方法cellForNextPageAtIndexPath-我收到一个错误:"UITablView"没有成员名称"cellForNextPageAtIndexPath"'.

I am implementing PFQueryTableViewController from Parse with sections and pagination. Because I am using sections, I need to set the 'load more' cell on my own. However, It seems that I can't access the method cellForNextPageAtIndexPath - I get an error: ''UITablView' does not have a member name 'cellForNextPageAtIndexPath' ' .

我环顾四周,关于该主题的唯一资源似乎是这个未解决的问题: /a>

I've looked around and the only resource on the subject seems to be this unanswered question: cellForNextPageAtIndexPath in swift

这是我的代码:

override func tableView(tableView: UITableView, cellForNextPageAtIndexPath indexPath: NSIndexPath) -> PFTableViewCell? {
    return PFTableViewCell()
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject!) -> PFTableViewCell? {


    let objectId = objectIdForSection((indexPath.section))
    let rowIndecesInSection = sections[objectId]!
    let cellType = rowIndecesInSection[(indexPath.row)].cellType
    var cell : PFTableViewCell


    if (indexPath.section == self.objects?.count) {
        cell = tableView.cellForNextPageAtIndexPath(indexPath) //'UITablView' does not have a member name 'cellForNextPageAtIndexPath'
    }


    switch cellType {
    case "ImageCell" :
        cell = setupImageCell(objectId, indexPath: indexPath, identifier: cellType)
    case "PostTextCell" :
        //cell = setupImageCell(objectId, indexPath: indexPath, identifier: "ImageCell")
        cell = setupTextCell(objectId, indexPath: indexPath, identifier: cellType)
    case "CommentsCell" :
        cell = setupCommentsCell(objectId, indexPath: indexPath, identifier: cellType)
    case "UpvoteCell" :
        cell = setupUpvoteCell(objectId, indexPath: indexPath, identifier: cellType)
    case "DividerCell" :
        cell = setupDividerCell(indexPath, identifier: cellType)
    default : print("unrecognised cell type")
        cell = PFTableViewCell()
    }
    cell.selectionStyle = UITableViewCellSelectionStyle.None

    return cell
}

推荐答案

我知道这有点晚了,但我只是想通了这一点,想与以后的访问者分享.

I know it's kind of late, but I just figured this out and wanted to share for future visitors.

如果要在解析中自定义常规的加载更多..."分页单元,请执行以下操作:

If you want to customize the usual "Load more..." pagination cell in parse, do the following:

1)创建一个新类,该类将PFTableViewCell子类化.出于演示目的,我们将其称为PaginationCell.

1) Create a new class that subclasses PFTableViewCell. For our demo purposes, we will call it PaginationCell.

2)用以下内容替换PaginationCell类的所有内容:

2) Replace all of the contents of the PaginationCell class with the following:

  import UIKit
  import Parse
  import ParseUI


 class PaginateCell: PFTableViewCell {



 override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: "paginateCell")


}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!
}

上面,我们刚刚使用了一个"paginateCell"的reuseIdentifier初始化了单元格.这将以编程方式设置复用标识符.

Above we just initialized the cell with a reuseIdentifier of "paginateCell." This programmatically sets the reuseIdentifier.

3)在您的PFQueryTableViewController中,实现以下方法:

3) In your PFQueryTableViewController, implement the following method:

   override func tableView(tableView: UITableView, cellForNextPageAtIndexPath indexPath: NSIndexPath) -> PFTableViewCell? {


}

3)创建一个nib文件.为了便于演示,我将文件名为paginateCellNib.xib.设计您想要的自定义单元格.请确保设置单元格的reuseIdentifier,并使其与上面的匹配.将自定义类设置为我们在上面创建的PaginationCell类,然后将所有IBoutlet连接到该类.

3) Create a nib file. For our demo purposes I'll call the file paginateCellNib.xib. Design the custom cell however you want. Be sure to set the cell reuseIdentifier and make it match the one above. Set the custom class to the PaginationCell class we created above, and connect all IBoutlets to this class.

4)现在,将上面的cellForNextPageAtIndexPath的内容替换为以下内容:

4) Now, replace the contents of the cellForNextPageAtIndexPath above with the following content:

    override func tableView(tableView: UITableView, cellForNextPageAtIndexPath indexPath: NSIndexPath) -> PFTableViewCell? {

    // register the class of the custom cell  
    tableView.registerClass(PaginateCell.self, forCellReuseIdentifier: "paginateCell")
    //register the nib file the cell belongs to
    tableView.registerNib(UINib(nibName: "paginateCellNib", bundle: nil), forCellReuseIdentifier: "paginateCell")

    //dequeue cell
    let cell = tableView.dequeueReusableCellWithIdentifier("paginateCell") as! PaginateCell

    cell.yourLabelHere.text = "your text here"





    return cell
}

这篇关于在swift2中看不到cellForNextPageAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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