cellForNextPageAtIndexPath not visible in swift2

148 views Asked by At

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' ' .

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

Here's my code:

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
}
1

There are 1 answers

0
jjjjjjjj On

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) Create a new class that subclasses PFTableViewCell. For our demo purposes, we will call it 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)!
}

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

3) In your PFQueryTableViewController, implement the following method:

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


}

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) 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
}