1

Я реализую PFQueryTableViewController из Parse с разделами и разбиением на страницы. Поскольку я использую разделы, мне нужно установить ячейку «загрузить больше» самостоятельно. Однако, похоже, что я не могу получить доступ к методу cellForNextPageAtIndexPath - я получаю сообщение об ошибке: «UITablView» не имеет имени участника «cellForNextPageAtIndexPath».cellForNextPageAtIndexPath не видно в swift2

Я посмотрел вокруг и единственный ресурс, на эту тему, кажется, этот вопрос без ответа: 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 
} 

ответ

3

Я знаю, что это своего рода поздно, но я просто понял, это и хотели поделиться для будущих посетителей.

Если вы хотите настроить обычную «Load больше ...» пагинация клетки в разборе, сделайте следующее:

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

Выше мы просто инициализируется ячейку с reuseIdentifier из «paginateCell.» Это программно устанавливает идентификатор повторного использования.

3) В вашем PFQueryTableViewController, реализовать следующий метод:

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


} 

3) Создать файл острия. Для наших демонстрационных целей я буду называть файл paginateCellNib.xib. Создайте пользовательскую ячейку, как хотите. Не забудьте установить идентификатор повторного использования ячейки и сделать его совпадающим с приведенным выше. Задайте собственный класс классу PaginationCell, который мы создали выше, и подключите все IBoutlets к этому классу.

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 
} 
Смежные вопросы