在 CollectionView -Objective-C 中显示/隐藏单元格

Posted

技术标签:

【中文标题】在 CollectionView -Objective-C 中显示/隐藏单元格【英文标题】:Show/Hide Cells in a CollectionView -Objective-C 【发布时间】:2013-03-30 11:29:44 【问题描述】:

我有一个 3 列和 20 行的集合视图。我只想显示前 3 行,并在集合视图的底部放置一个“显示更多”按钮。当用户触摸按钮时,其他行将可见。 我不能这样做。所以我创建了两个不同的集合视图,第一个集合视图只包含我想第一次显示的 3 行,单击按钮后,其他集合视图显示。 有一个更容易做到这一点?我只想用一个 collectionview 来做这个?

【问题讨论】:

为什么你认为你不能这样做?只需更改collectionView:numberOfItemsInSection: 的返回值并调用reloadData 即可添加单元格。 【参考方案1】:

如果你有一个 NSMutableArray 作为数据源:

-(void)buttonShowMoreClicked 
  [self.collectionView performBatchUpdates:^
    [self.dataSourceArray addObjectsFromArray:arrayContainingInfoAboutOther17Rows];
    [self.collectionView insertItemsAtIndexPaths:arrayOfIndexPaths];
   completion:nil];


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
    return self.dataSourceArray.count;

【讨论】:

以上是关于在 CollectionView -Objective-C 中显示/隐藏单元格的主要内容,如果未能解决你的问题,请参考以下文章

无法在 collectionView 内调用 dequeueReusableCellWithReuseIdentifier(collectionView:collectionViewLayout:si

CollectionView 在 tableViewCell 数据显示

CollectionView 中的 CollectionView:使用 didSelectItemAt 执行Segue

CollectionView 里面的 CollectionView | CollectionViewCell 自动布局错误

Collectionview 的底部约束未在运行时更新

当collectionView折叠时隐藏collectionView内容