The cell in question has a disclosure option set as:
let disclosureOptions = UICellAccessory.OutlineDisclosureOptions(style: .header)
let accessory: UICellAccessory = .outlineDisclosure(options: disclosureOptions)
cell.accessories = [accessory]
My requirement is to keep only one item in the whole section expandable.
I observe for the collapse and expansion changes below:
dataSource.sectionSnapshotHandlers.willCollapseItem = { [weak self] item in
guard let self = self else { return }
if item == self.expandedArticleItem {
self.expandedArticleItem = nil
}
}
dataSource.sectionSnapshotHandlers.willExpandItem = { [weak self] item in
guard let self = self else { return }
if self.expandedArticleItem == nil {
self.expandedArticleItem = item
} else {
guard let sectionForItem = self.dataSource
.snapshot()
.sectionIdentifier(containingItem: item),
let expandedItem = self.expandedArticleItem
else { return }
var sectionSnapshot = self.dataSource.snapshot(for: sectionForItem)
sectionSnapshot.collapse([expandedItem])
self.dataSource.apply(sectionSnapshot, to: sectionForItem,
animatingDifferences: false)
self.expandedArticleItem = item
}
}
This code does the job of keeping only item expanded but the default disclosure indicator still points down "v" for cells that is not visible currently but was earlier expanded and is now collapsed.