swift - cellForNextPageAtIndexPath 在 swift2 中不可见

标签 swift parse-platform swift2 pfquerytableviewcontrolle pftableviewcell

我正在从带有部分和分页的 Parse 中实现 PFQueryTableViewController。因为我正在使用部分,所以我需要自己设置“加载更多”单元格。但是,我似乎无法访问 cellForNextPageAtIndexPath 方法 - 我收到错误消息:“UITablView”没有成员名称“cellForNextPageAtIndexPath”。

我环顾四周,关于这个主题的唯一资源似乎是这个未回答的问题: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
}

最佳答案

我知道有点晚了,但我只是想通了这一点,并想与 future 的访客分享。

如果您想在解析中自定义通常的“加载更多...”分页单元格,请执行以下操作:

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

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

  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 初始化了单元格。这以编程方式设置了 reuseIdentifier。

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

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


}

3) 创建一个 nib 文件。为了我们的演示目的,我将调用文件 paginateCellNib.xib。根据需要设计自定义单元格。请务必设置单元格 reuseIdentifier 并使其与上面的匹配。将自定义类设置为我们在上面创建的 PaginationCell 类,并将所有 IBoutlet 连接到该类。

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

    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
}

关于swift - cellForNextPageAtIndexPath 在 swift2 中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31860990/

相关文章:

ios - swift 中 MVC 的困惑

iOS 呈现 View Controller 动画为 'Push'(左右动画)

ios - 在 Swift 中加载具有透明背景的 MPMoviePlayerViewController?

java - App 从解析初始化恢复返回后,在主线程上获取网络异常

Android服务在推送通知发送时启动并在服务任务完成后停止

swift - 通过关系列出好友列表

ios - Swift WKWebView 与 Javascript 交互

swift - 如何使用 Swift 2 在 iOS 应用程序中使用音频?

ios - 使用 iOS 图表进行交互式跟踪。如何

ios - UIMenuController 未显示在 textView 中