我有10张照片,我在集合视图中显示。还有两个按钮应该对这个集合视图进行排序。当我启动应用程序时,应该显示1-5单元和其他隐藏的单元格。当我单击第二个按钮时,这些单元格将被隐藏,另一个将出现。我如何实现这一点?
ViewController
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
}发布于 2020-07-08 14:16:07
集合视图有数据的后备存储(通常是数组)。此备份存储不一定总是完整的备份存储。只需创建其他备份存储,其中包含要在此特定时刻显示的数据。
https://stackoverflow.com/questions/62796397
复制相似问题