When reloading a ListSectionController inside a ListStackedSectionController, the entire ListStackedSectionController is reloaded.
Note: self refers to a ListSectionController which is inside a ListStackedSectionController
self.collectionContext?.performBatch(animated: true, updates: { (batchContext) in
batchContext.reload(self)
})
IGListKit version: 3.1.1@Marcocanc ya this is intended behavior atm. Can you tell me what behavior you would expect?
@rnystrom
Here's an example ListStackedSectionController:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HeaderSectionController โ ListSingleSectionController
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โ
โ โ
โ โ ListSectionController
โ ContentSectionController โ (variable number of cells)
โ โ
โ โ
โ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ FooterSectionController โ ListSingleSectionController
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
calling batchContext.reload(self) from the ContentSectionController I would expect only that controller to reload. Instead the other two are reloaded as well
Is there another way to only reload all cells inside a nested ListSectionController?
@Marcocanc , I just came across the same situation as you did. Below is my way of work around:
extension ListSectionController {
fileprivate var stackedSectionController: ListStackedSectionController? {
if collectionContext is ListStackedSectionController {
// swiftlint:disable:next force_cast
return (self.collectionContext as! ListStackedSectionController)
} else {
return nil
}
}
}
extension ListStackedSectionController {
fileprivate var sectionControllers: NSOrderedSet? {
if responds(to: Selector(("sectionControllers"))) {
let unmanaged = perform(Selector(("sectionControllers")))
if unmanaged?.takeUnretainedValue() is NSOrderedSet? {
// swiftlint:disable:next force_cast
return unmanaged?.takeUnretainedValue() as! NSOrderedSet?
}
}
return nil
}
}
and use like this:
if let sectionControllers = strongSelf.stackedSectionController?.sectionControllers,
// swiftlint:disable:next force_cast
strongSelf === (sectionControllers.firstObject as! ListSectionController) {
strongSelf.collectionContext?.performBatch(animated: false, updates: { (batchContext) in
batchContext.reload(in: strongSelf, at: [0])
})
} else {
strongSelf.collectionContext?.performBatch(animated: false, updates: { (batchContext) in
batchContext.reload(strongSelf)
})
}
here I reload the first item of stackedSectionController, cause in my case I need to reload the first sub section controller, and that sub section controller only has one item. In your case, if's need a little extra work to calculate the real indexes you want to reload.