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

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

【问题讨论】:

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

标签: iphone ios uicollectionview


【解决方案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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 2018-10-18
    • 2011-03-18
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多