Swift Beginner: UICollectionView — Different Methods to Reload the Data

José Ney Guerrero
DAK42
Published in
2 min readOct 17, 2018
“four orange, green, blue, and red paint rollers” by David Pisnoy on Unsplash

I love CollectionView, is one of the most versatile components of UIKit. In this short post I’ll share the different methods that we can use to reload the data and some use cases.

reloadData()

This is the most used method, this reloads all the data, refreshing all the cells in the CollectionView this is what you should use if you have a Collection View that loads all the data at the same time, one common use case is when you have just one API call

collectionView.reloadData()

reloadSections(_:)

This method works great when you have different sections that load different data (like when you have different API calls), for example, you have one section that loads weather data from darksky.net other section that show cells with newspapers articles with data from another API

reloadItems(at:)

With this method you can implement specific cells to be reloaded. This could be used when the state of some data is modified.

For example in an app like WhatsApp when you send a message, it gets added to the Collection View immediately but the app is waiting the server confirmation, when the confirmation returns and it’s OK you could update the cell to reflect the state change with one check or show a different icon reflecting the send error.

collectionView.reloadItems(at: changedIndexPaths)

--

--