首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在集合视图中显示特定单元格。斯威夫特

在集合视图中显示特定单元格。斯威夫特
EN

Stack Overflow用户
提问于 2020-07-08 13:52:29
回答 1查看 402关注 0票数 0

我有10张照片,我在集合视图中显示。还有两个按钮应该对这个集合视图进行排序。当我启动应用程序时,应该显示1-5单元和其他隐藏的单元格。当我单击第二个按钮时,这些单元格将被隐藏,另一个将出现。我如何实现这一点?

ViewController

代码语言:javascript
复制
let practice = true

@IBAction func theoryButtonAction(_ sender: UIButton) {
   
    practice = false
    collectionView.reloadData()
}
@IBAction func practiceButtonAction(_ sender: UIButton) {

    practice = true
    collectionView.reloadData()
}
    
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
    guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: GameCollectionViewCell.identifier, for: indexPath) as? GameCollectionViewCell else {
        return UICollectionViewCell()
    }
     
    let game = gamesList[indexPath.row]

    cell.gameLabel.text = game.name.localized
    cell.gameLabel.roundCorners(.allCorners, radius:cell.gameLabel.frame.height / 2 )
    cell.contentView.roundCorners(.allCorners, radius: 50.0)
    
    /*
        if practice = true. Hide cell 1-5 and show 5-10
        if practice = false Hide cell 5-10 and show 1-5
    */
  
    return cell
}
EN

回答 1

Stack Overflow用户

发布于 2020-07-08 14:16:07

集合视图有数据的后备存储(通常是数组)。此备份存储不一定总是完整的备份存储。只需创建其他备份存储,其中包含要在此特定时刻显示的数据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62796397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档