LampShade
LampShade

Reputation: 2775

CollectionView.DeleteItems throws exception NSInternalInconsistencyException

I'm getting this exception when I try to call DeleteItems on my UICollectionView. I've googled around and most people are saying they solve this by NOT calling ReloadData on the CollectionView after they call DeleteItems, but I know I'm not calling that. I even overrode it and put a break point on ReloadData and confirmed that it's not getting called.

this.InvokeOnMainThread(() => 
{
    CollectionView.DeleteItems (new NSIndexPath [] { indexPath });
});

Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (5) must be equal to the number of items contained in that section before the update (5), 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).

Upvotes: 0

Views: 424

Answers (1)

LampShade
LampShade

Reputation: 2775

Looks like I needed to update my list that was tied to my datasource BEFORE calling DeleteItems:

this.InvokeOnMainThread(() => 
{
    this.MyList.RemoveAt(indexPath.Row);
    CollectionView.DeleteItems (new NSIndexPath [] { indexPath });
});

Upvotes: 1

Related Questions