Carpetfizz
Carpetfizz

Reputation: 9169

How can I reload only updated cells from UICollectionView

I have several cells that are written onto a UICollectionView and reloading them takes a long time. How can I reload only when the data of a cell is modified? Here's one thing I've tried:

  if([oldDataSource count] != [currentDataSource count])
   {
      [collectionView reloadData];
   }

Yet, I still don't want to deal with reloading the entire thing. I've also tried:

if([oldDataSource count] < [currentdataSource count])
{
//something was added. //reload the last item in the current data source 
}

This also failed because I can't reload something that doesn't "exist" in memory yet. This method also doesn't work because if something was deleted from my data source, the Cell will still remain in the interface, and will crash if clicked on.

So, what's the best way to deal with edited cells?

Thanks!

Upvotes: 0

Views: 1724

Answers (2)

devluv
devluv

Reputation: 2017

try and get the cell u want to change. then:-

  1. If u can get it. change the data source and reload it.
  2. if it doesnt reflect the changes. change the data source, then the repective new values of the cell, then call setNeedsDisplay on the cell.
  3. If the cell is not returned (that means) it is out of the view. Simply change the data source. The change in the data source will be reflected when the cell is brought to view

try any of these three. cheers. have fun

Upvotes: 1

Rushabh
Rushabh

Reputation: 3203

Reloads just the items at the specified index paths.

- (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths

Discussion Call this method to selectively reload only the specified items. This causes the collection view to discard any cells associated with those items and redisplay them.

Upvotes: 2

Related Questions