Kevin Science Kevin Science - 10 months ago 33
iOS Question

ActivityIndicator is not showing on CollectionViewCell

I want to present activityIndicator animating when I click a collectionviewCell. But it doesn't work, and I could not find out the problem. ActivityIndicator is defined in the Custom collectionViewCell class.

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

VMSListCell *cell = [_myCollectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Inside of main queue with activityindicator");
cell.activityIndicator.hidden = false;
[cell.activityIndicator startAnimating];
NSLog(@"After main queue");

I am using a custom cell. Logs prints "Inside of main queue with activity indicator", but not "After main queue". And There is no activityIndicator spinning.

Because I will do a http request, after click collectionviewCell, I put activity animating method inside of main queue. I have also tried without main queue, it doesn't work either.


The problem is with this line

VMSListCell *cell = [_myCollectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];

In, didselect method, you are taking reusable cell, it will never work, it is fine for cellforItemAtIndexPath method, but it is totally wrongFor didSelectItemAtIndexPath method.

Change above line to this

VMSListCell *cell = [_myCollectionView cellForItemAtIndexPath:indexPath];