FranticRock
FranticRock

Reputation: 3283

UICollectionView didSelectItemAtIndexPath takes a long time to fire (2-3 seconds)

I have a UICollectionView embedded in a Subclass that is a UIView.
That UIView is loaded from a NIB and contains the UICollectionView for which there is an IBOutlet.

The UICollectionView delegate and datasource are set to this UIView in the view's awakeFromNib.

When the user presses a Cell in the UICollectionView, the following method takes 2-3 seconds to get called on an iPhone 4s:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

On a faster phone, it's faster and more responsive (but you can tell that it's still not as responsive as it should be). It should be very fast on a 4s As well. The 4s is running 9.3 (I expect a time of 20-40 MS, not longer).

Currently it performs very sluggishly from a UX perspective.

So is perhaps the UI thread too loaded up for the didSelect method to be allowed to breathe? (Note: other UI actions are fast).

Upvotes: 0

Views: 288

Answers (1)

FranticRock
FranticRock

Reputation: 3283

The problem was: In my cell class, i had an UIImageView and I was setting a large image (Dimensions over 1300 by 1300), and making it a template (so 2 images loaded), and then applying a Tint color to it. I was doing this operation in cellForRow... And although that code is not getting called on didSelect, the sheer size of the image itself and the scaling of it was causing the slow down in didSelect when selecting the cell.

I replaced it with a 128 by 128 image, and the same code works fast now.

Upvotes: 3

Related Questions