I have a collectionView which tries to implement infinite horizontal scrolling.
The idea is that after a certain offset.x, I insert new items in performBatchUpdates
and this is how I get my new cells.
I get the following exception inserting an array on indexPaths:
'NSInternalInconsistencyException', reason: 'attempt to insert section 9223372036854775807 but there are only 1 sections after the update'
Here is the code when I add the indexPaths:
func scrollRight() {
var indexPaths = [IndexPath()]
for i in 0..<7 {
indexPaths.append(IndexPath(item: i, section: 0))
}
collectionView.performBatchUpdates({
numberOfItems += 7
collectionView.insertItems(at: indexPaths)
for i in 0..<7 {
days[i] -= 7
}
}, completion: nil)
indexPaths.removeAll()
for i in 7..<14 {
indexPaths.append(IndexPath(item: i, section: 0))
}
collectionView.performBatchUpdates({
numberOfItems -= 7
collectionView.deleteItems(at: indexPaths)
}, completion: nil)
}
That is triggered in ScrollViewDidEndDragging,
any ideas why would it do that? There is only one section; also I update my dataSource for the numberOfItemsInSection
before I get the indices inserted. Thanks for any help!