How to update cell size in UICollectionView after setting cell data?

So, I have a UICollectionView with a different image of a different size in each cell. When cellForItemAtIndexPath is called: I update the UICollectionViewCell with a method that retrieves the image asynchronously on the Internet and displays its full size.

My problem is that my cell size is already set using sizeForItemAtIndexPath. I would like this to be called, so the cell has a loaded image size.

How can i do this?

+1
ios uicollectionview
source share
2 answers

If you have already set your size, find the index of the cell you want to update:

NSIndexPath * indexPathOfCellToResize = // index path of cell to refresh [myCollectionView reloadItemsAtIndexPaths:@[indexPathOfCellToResize]]; 

Probably the best way to do this, but something works here:

Create a delegate protocol in your cell

 @protocol CellDelegate - (void) imageIsReadyForCell:(id)cell; @end 

Delegation Property

 @property (strong, nonatomic) id<CellDelegate>delegate; 

In the cell, when the image has finished the call:

 [self.delegate imageIsReadyForCell:self]; 

Then in your file the View collection is placed in the interface

 @interface SomeViewController : UIViewController <CellDelegate> 

And in .m

 - (void) imageIsReadyForCell:(id)cell { NSIndexPath * indexOfReadyCell = [yourCollectionView indexPathForCell:cell]; [myCollectionView reloadItemsAtIndexPaths:@[indexPathOfReadyCell]]; } 
+2
source share

Not an answer, but I don't have enough reputation for comment.

I'm trying to update my collection, and I put a download under the image:

 [self.delegate imageReadyForCell:cell] 

But this does not change anything, I set breakpoints inside the imageReadyForCell method, but it does not even reach it. I followed all the steps, as was done above, with protolcol and the property for the CellDelegate delegate, and I was not able to get this work to work.

0
source share

All Articles