ActivityIndi​​cator 未显示在 CollectionViewCell 上

ActivityIndicator is not showing on CollectionViewCell

我想在单击 collectionviewCell 时呈现 activity 动画指示器。但它不起作用,我找不到问题所在。 ActivityIndi​​cator 定义在 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");
}

我正在使用自定义单元格。日志打印 "Inside of main queue with activity indicator",但不打印 "After main queue"。并且没有 activity指标旋转。

因为我会做一个http请求,点击collectionviewCell后,我把activity动画方法放在主队列里面。我也试过不用主队列,也没用

问题出在这一行

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

在,didselect方法中,你取的是reusable cell,它永远不会起作用,cellforItemAtIndexPath方法没问题,但是didSelectItemAtIndexPath方法是完全错误的。

将上面的行更改为此

VMSListCell *cell = [_myCollectionView cellForItemAtIndexPath:indexPath];