-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cell reordering in a ListBindingSectionController - problems with the data source #1262
Comments
It definitely seems like the binding SC is missing a call to rearrange its view models when moving happens. I found that adding this to the binding SC: - (void)moveObjectFromIndex:(NSInteger)sourceIndex toIndex:(NSInteger)destinationIndex {
NSMutableArray *viewModels = [self.viewModels mutableCopy];
[viewModels exchangeObjectAtIndex:sourceIndex withObjectAtIndex:destinationIndex];
self.viewModels = viewModels;
} And then changing your implementation to: override func moveObject(from sourceIndex: Int, to destinationIndex: Int) {
super.moveObject(from: sourceIndex, to: destinationIndex)
groupModel.models.swapAt(sourceIndex, destinationIndex)
} Fixes the issue. Using @d3mueller are you interested in submitting a fix for this? Would be an awesome contribution! Also thanks a ton for sending us an example! |
Thanks! That method looks like the solution. But shouldn't the objects in the array be moved instead of swapped? After swapping, the This seems to be working: - (void)moveObjectFromIndex:(NSInteger)sourceIndex toIndex:(NSInteger)destinationIndex {
NSMutableArray *viewModels = [self.viewModels mutableCopy];
id removedModel = [viewModels objectAtIndex:sourceIndex];
[viewModels removeObjectAtIndex:sourceIndex];
[viewModels insertObject:removedModel atIndex:destinationIndex];
self.viewModels = viewModels;
} override func moveObject(from sourceIndex: Int, to destinationIndex: Int) {
super.moveObject(from: sourceIndex, to: destinationIndex)
let object = groupModel.models.remove(at: sourceIndex)
groupModel.models.insert(object, at: destinationIndex)
} Yes, I'd love to try and contribute 😀. |
Oh duh ya, shouldn’t be swapped. But yes this would be a really great contribution! We would want to make sure binding SC subclasses are required to call Sent with GitHawk |
General information
IGListKit
version: master branchHey,
I've seen the examples showcasing how to implement cell reordering using IGListKit. For the past 2 days, I've been trying to implement this, but inside a
ListBindingSectionController
. There is strange behavior that I don't understand.I've managed to implement the reordering, kind of. It is working, but it has some problems:
I recorded this and uploaded a gif:
The strange thing is that the array containing the models for the cell is actually correct (even after moving or deleting).
I'm pretty sure, I've implemented the move functionality in a way that's causing these problems:
I tried calling
update(animated: false, completion: nil)
(to update the internalviewModels
array) after moving the model, but that leads to more strange behavior (cells are being re-rendered with the wrong viewModel, like 2. from above but without deleting a cell first)I created a demo project showing this:
Link to demo project: https://github.com/d3mueller/ReorderExample
I don't really know what to do. I can't find my mistake. Maybe I don't quite understand how
ListBindingSectionController
works. I'd appreciate any help with this :)Thanks and have a nice day,
Dennis
SectionController class from the demo project:
Debug information
The text was updated successfully, but these errors were encountered: