1

我为 UITableViewcontroller 中的一个部分创建了一个自定义标题。我正在使用 NFR 来获取数据。在该部分的行中,我可以选择删除。当用户删除数据时,NFR 会更新数据并从列表中删除该行。但是,自定义标头也将被删除。

下面是代码库

覆盖 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{

    let  headerCell = tableView.dequeueReusableCellWithIdentifier("headerCell") as? PendingPaymentHeaderCell
    if let cell = headerCell {
        cell.label1.text = "test"
        cell.timeLabel.text = "test"

    }

    return headerCell

}

override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 60.00
}

覆盖 func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { true }

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cellIdentifier = "pendingPaymentTableViewCell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! PendingPaymentCell
    configureCell(cell, atIndexPath: indexPath)
    return cell

}



// MARK: -  FetchedResultsController Delegate

func controllerWillChangeContent(controller: NSFetchedResultsController) {
    tableView.beginUpdates()
}

func controllerDidChangeContent(controller: NSFetchedResultsController) {
     tableView.endUpdates()
}


func controller(
    controller: NSFetchedResultsController,
    didChangeSection sectionInfo: NSFetchedResultsSectionInfo,
    atIndex sectionIndex: Int,
    forChangeType type: NSFetchedResultsChangeType) {

    print("change type is \(type.rawValue)")
    let sectionIndexSet = NSIndexSet(index: sectionIndex)
                switch type {
        case .Insert:
            print("insert")
            self.tableView.insertSections(sectionIndexSet, withRowAnimation: UITableViewRowAnimation.Fade)
            break
        case .Delete:
            print("delete")
             self.tableView.deleteSections(sectionIndexSet, withRowAnimation: UITableViewRowAnimation.Fade)

            break
        case .Move :
            break
        case .Update :
            break

        }

}



func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
    switch (type) {
    case .Insert:
        if let indexPath = newIndexPath {
            tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        }
        break;
    case .Delete:

        if let indexPath = indexPath {
            print("deleting \(indexPath)")
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
                    }


            break;

    case .Update:
        if let indexPath = indexPath {
            let cell = tableView.cellForRowAtIndexPath(indexPath) as! PendingPaymentCell
            configureCell(cell, atIndexPath: indexPath)
        }
        break;

    case .Move:
        if let indexPath = indexPath {
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        }

        if let newIndexPath = newIndexPath {
            tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade)
        }
        break;
    }
}

对此的任何帮助将不胜感激。

问候, 森迪尔

4

0 回答 0