개발/swift

Swift UICollectionView performBatch

lemonade 2020. 11. 4. 10:00
반응형

UICollectionView performBarch

 

Almost every app use UICollectionView. 

In case of using UICollectionView, there is lovely function comes in, reloadData. 

With this function, the whole list is refreshed with completely new content. 


But it makes the UICollectionView reinvalidate cell sizes again, which can reduce performance.

Further, it makes blink animation which give users odd experience.
It’s better manually insert and delete of rows.

 


You can use the performBatchUpdates(_:completion:) method when you want to animate multiple separate changes into place at the same time.  See the description of that method for more information.

 


Be careful!

Deletes are processed before inserts in batch operations. This means the indexes for the deletions are processed relative to the indexes of the collection view’s state before the batch operation, and the indexes for the insertions are processed relative to the indexes of the state after all the deletions in the batch operation. 

 

That means you must operate delete first. !

 

 

Document)

Official Doc

 

Apple Developer Documentation

 

developer.apple.com




Addition)

How to know reload complete?

 

반응형
그리드형

'개발 > swift' 카테고리의 다른 글

Swift everything about launch screen  (0) 2020.11.07
Swift how to fix autolayout issue?  (0) 2020.11.05
Swift mutating function  (0) 2020.11.01
Swift How to manage keyboard with UIScrollView?  (0) 2020.10.29
Swift How to save data? Userdefaults  (0) 2020.10.28