I hope it is ok to ask this here. Otherwise, please feel free to delete this thread.
final class SectionModel: IGListDiffable {
let id: String
let name: String
var cells: [CellModel]
...
}
final class CellModel: IGListDiffable {
let id: String
var name: String
...
}
var data: [CellModel] = [...]self.data[0].cells[0].name = "****"
adapter.performUpdates(animated: true)
This does not work, as the model object is class object, the value been changed before compare the value by the adapter (adapter has no way to know if something changed)
self.data[0].cells[0].name = "****"
adapter.reloadData()
This works, but reload all sections (cells)
let obj = self.data[0].cells[0]
obj.name = "****"
adapter.reloadObjects([obj])
This works, but reload all the cells in the whole section
If as preceding not to recreate all the model objects (recreate self.data, just directly change the properties), what's the suitable way to update a specific cell related updated cell model object?
Does IGListKit support to move cell by gesture? If we have to write code to do it, how to update the model object after moving?
Thanks,
I hope it is ok to ask this here
All questions welcome!
what's the suitable way to update a specific cell related updated cell model object?
If you're modifying data that represents something at the cell-level, the modifications and storage should probably happen within the section controller and not up at the view controller. Within the section controller you can then do something like:
self.cells[0].name = "Hello!"
self.collectionContext?.reload(in: self, at: 0)
Does IGListKit support to move cell by gesture?
This is unsupported at the moment, but I'll open an issue to track this because I think its something we could add in the future pretty easily.
Thanks much @rnystrom, it works.
And I'd like to see there is delegate to control the moving, like the suggestion:
allowMove(from index: Int) -> Bool
allowMove(to index ...) -> Bool
And allow to disable/enable moving feature.
I have another question related to that.
If you add or remove CellModels from SectionModel -> [cells], from VC adapter.performUpdates(animated: true) doesn't update the UI. Only reloadData() works. But it's not what I wanted.
How can I update UI for updated cells array in SectionModel from VC.
Thanks!
@shuhrat10 performUpdates(animated:,completion:) only works for section-level operations. If you want to do item updates you can do that directly from the section controller using the insert, delete, and reload operations. We're planning on adding moves in #145 for 3.0.0.
To make this more streamlined when your cells are powered by an array of view models, we're also planning #38 so this is more automated.
@rnystrom That will be awesome, I can't wait to see this functionality.