After removing the last item in a section, the goal is to remove the entire section, including its header, from the UICollectionView.
Unfortunately, the section header persists even though there is no section in the underlying data model.
Refreshing the view -- by popping it from the navigation stack and navigating back to the view -- correctly shows the UICollectionView
with the section header removed.
In the test case, there is only one section so the UICollectionView
should become blank after removing the final item.
Suggestions?
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
print("# sections: \(USER.getSections().count)")
return USER.getSections().count
}
// Delete item
let indexPath = view.indexPathsForSelectedItems()![0]
let section = USER.getSections()[indexPath.section]
USER.removeItemAt(section, index: indexPath.row)
view.deleteItemsAtIndexPaths([indexPath])
// Update one section or entire view
if (section.getNumItems() > 0) {
view.reloadSections(NSIndexSet(index: indexPath.section))
} else {
view.deleteSections(NSIndexSet(index: indexPath.section))
view.reloadSections(NSIndexSet(index: indexPath.section))
view.reloadData()
}