你的问题似乎与核心数据无关。如果我说得对,您只需要一种方法来获取对应于索引路径部分的标头。
This method
可以使用:
// Any place, where you have your index path.
let header = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionHeader,
at: indexPath)
// Update header any way you like.
例如:
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>,
didChange anObject: Any,
at indexPath: IndexPath?,
for type: NSFetchedResultsChangeType,
newIndexPath: IndexPath?) {
switch type {
case .insert:
// Insert a cell to the index path.
case .delete:
// Delete the cell at the index path.
case .move:
// Move the cell at the index path to the new index path.
case .update:
// Update the cell at the index path.
// Update your header.
let header = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionHeader,
at: indexPath)
header.text = "Updated" // Or whatever.
}
}
(
This question
和
this also
可能也有帮助。)