我为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视图:UIView,forSection section:Int){ 真正 }
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;
}
}
对此的任何帮助将不胜感激。
此致 Sendhil