Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView update a single cell

People also ask

How do I load a collectionView cell?

Get the selected Superhero object ( selectedHero ) from the diffable data source using the index path. Append “★” to selectedHero 's name . Make a copy of the current diffable data source snapshot, so that we can modify it later. Modify the new copy of diffable data source snapshot by reloading selectedHero within it.

What is the difference between Uitableview and UICollectionView?

Tableiw is a simple list, which displays single-dimensional rows of data. It's smooth because of cell reuse and other magic. 2. UICollectionView is the model for displaying multidimensional data .


- (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths

Here it is a method to reload the specific indexPaths in your collectionView


Dinesh's answer is spot-on. But to avoid unwanted animations when reloading (aka "flashing") use:

BOOL animationsEnabled = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[myCollectionView reloadItemsAtIndexPaths:myIndexPaths];
[UIView setAnimationsEnabled:animationsEnabled];

See Inserting, Deleting, and Moving Sections and Items from the "Collection View Programming Guide for iOS":

To insert, delete, or move a single section or item, you must follow these steps:


Update the data in your data source object. Call the appropriate method of the collection view to insert or delete the section or item. It is critical that you update your data source before notifying the collection view of any changes. The collection view methods assume that your data source contains the currently correct data. If it does not, the collection view might receive the wrong set of items from your data source or ask for items that are not there and crash your app.


So in your case, you must add an image to the collection view data source first and then call insertItemsAtIndexPaths. The collection view will then ask the data source delegate function to provide the view for the inserted item.