ActivityIndi​​cator未在CollectionViewCell上显示

时间:2016-07-04 06:56:43

标签: ios objective-c uicollectionview uicollectionviewcell uiactivityindicatorview

我想在点击collectionviewCell时显示activityIndi​​cator动画。但它没有用,我找不到问题。 ActivityIndi​​cator在Custom collectionViewCell类中定义。

- (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");
}

我正在使用自定义单元格。日志打印"主要队列内部带有活动指示符"但不是"在主队列"之后。并且没有活动指示器旋转。

因为我会做一个http请求,点击collectionviewCell后,我把活动动画方法放在主队列中。我也尝试过没有主要队列,它也没有工作。

1 个答案:

答案 0 :(得分:3)

问题在于这一行

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

在,doselect方法中,你正在使用可重用的单元格,它永远不会工作,对于cellforItemAtIndexPath方法来说很好,但对于didSelectItemAtIndexPath方法来说是完全错误的。

将上一行改为此

VMSListCell *cell = [_myCollectionView cellForItemAtIndexPath:indexPath];
相关问题