Run BatchUpdates after viewDidDisppear causing the error?

I'm calling

performBatchUpdates({
            self.insertItemsAtIndexPaths(indexPathes)
            },
            completion: {
                _ in
        })

in the form of a collection that is not displayed in the controller! there are already other view controllers that are advancing over it.

this will result in the following error:

Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (12) must be equal to the number of items contained in that section before the update (12), plus or minus the number of items inserted or deleted from that section (12 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

but it’s not, because if I call executeBatchUpdates while the view is visible, it will work fine.

what happened exactly?

EDIT: Remember that if I call reloadData, it works fine until the view is displayed. what do apples say about this?

How can I catch this exception. so that i could user reloadData instead?

EDIT: I printed the following before calling performBachUpdates:

print("visibleCells().count :"  + String(self.visibleCells().count))
print("dataModel count:" + String(self.dataArray.count))

here is what i got:

visibleCells().count :0
dataModel count:12

this means the exception is wrong !!

+4
source share
1

@rmaddy, , .
insertItemsAtIndexPaths indexPathes ( 12 ), 12 12 . , - (, - dataModel.insert("whatever", atIndex: 0), insertItemsAtIndexPaths 0).
, , (12). reloadData, ( , )

reloadData , / -, , . insertItemsAtIndexPaths , , , ( , ) , .
( @try/catch) , - , .

+1

All Articles