【问题标题】:Reload footerView of UICollectionViewCell with reloadItemsAtIndexPaths使用 reloadItemsAtIndexPaths 重新加载 UICollectionViewCell 的 footerView
【发布时间】:2014-05-16 21:13:05
【问题描述】:

我正在使用 CollectionView 来显示数据。当用户按下某个按钮时,我正在刷新 CollectionViewCell 以反映如下更改:

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

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

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

当我重新加载单元格时不会调用它。

如果我用 [self.collectionview reloadData] 重新加载整个集合视图,一切都可以工作,但这并不高效。

如何确保我的 UICollectionViewCell 在 indexPath 的页脚也被刷新?

【问题讨论】:

    标签: ios layout uicollectionview uicollectionviewcell


    【解决方案1】:

    您必须使布局或重新加载部分。

    1. 使布局无效。

      [[_collectionView collectionViewLayout] invalidateLayout]
      
    2. 重新加载该部分。使用reloadSections: 更新UICollectionView 中的1 个或多个部分。

      [self.collectionView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)]];
      

    【讨论】:

    • 我都按照这个顺序实现了,它解决了我的问题,谢谢!对于那些有同样问题并想知道应该在 NSMakeRange 中使用什么值的人:NSMakeRange 与(位置,长度)一起使用。 NSMakeRange(startIndex, endIndex-startIndex)。因为我想刷新 indexPath.row 的元素,所以我使用了 NSMakeRange(indexPath.row, indexPath.row)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多