Instagram / IGListKit

A data-driven UICollectionView framework for building fast and flexible lists.
https://instagram.github.io/IGListKit/
MIT License
12.88k stars 1.54k forks source link

How to delete Items in ListBindingSectionController #1338

Open LeeFengHY opened 5 years ago

LeeFengHY commented 5 years ago

New issue checklist

General information

Debug information

erminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (3) must be equal to the number of items contained in that section before the update (3), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).

# Please include debug logs using the following lldb command:
po [IGListDebugger dump]

This is my code ,I want to delete this item but crash

func deleteComment(_ comment: CommentListData) {
        guard let index = sectionObjects.firstIndex(of: comment) else {
            return
        }

        self.collectionContext?.performBatch(animated: true, updates: { (batchContext) in
            self.sectionObjects.remove(at: index)
            batchContext.delete(in: self, at: IndexSet(integer: deleteIndex))
        }, completion: nil)
    }
chenjunpu commented 5 years ago

You can try to use this method to change ListBindingSectionControllerDataSource

/**
 Tells the section controller to query for new view models, diff the changes, and update its cells.

 @param animated A flag indicating if the transition should be animated or not.
 @param completion An optional completion block executed after updates finish. Parameter is YES if updates were applied.
 */
- (void)updateAnimated:(BOOL)animated completion:(nullable void (^)(BOOL updated))completion;