使用reloadItemsAtIndexPaths重新加载UICollectionViewCell的footerView

时间:2014-05-16 21:13:05

标签: ios layout uicollectionview uicollectionviewcell

我使用CollectionView来显示数据。当用户按下某个按钮时,我刷新了CollectionViewCell以反映这样的变化:

[self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];

这可以很好地重新加载单元格,除了它没有重新加载它的页脚视图。我实现了以下方法

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"FOOTER CALLED");

重新加载单元格时,这不会被调用。

如果我用[self.collectionview reloadData]重新加载整个集合视图,Eveything会起作用,但效率不高。

如何确保indexPath上我的UICollectionViewCell的页脚也会刷新?

1 个答案:

答案 0 :(得分:1)

您必须使布局无效重新加载该部分。

  1. 布局无效。

    [[_collectionView collectionViewLayout] invalidateLayout]
    
  2. 重新加载该部分。使用reloadSections:更新UICollectionView

    中的1个或多个部分
    [self.collectionView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)]];