[英]Show specific cells in collection view. Swift
我在收藏視圖中顯示了 10 張圖片。 還有兩個按鈕應該對這個集合視圖進行排序。 當我啟動應用程序時,應顯示 1-5 個單元格和其他隱藏的單元格。 當我點擊第二個按鈕時,這些單元格應該被隱藏並且會出現另一個。 我該如何實施?
視圖控制器
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
}
您的集合視圖有一個數據的后備存儲(通常是一個數組)。 該后備存儲不必總是完整的后備存儲。 只需創建其他后備存儲,其中包含您要在此特定時刻顯示的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.