美文网首页
CollectionView基础动态列表

CollectionView基础动态列表

作者: wenju | 来源:发表于2021-08-12 11:45 被阅读0次

// 实现效果如下图,点击文字,改变选中文字的颜色


图片.png

该代码为伪代码,注意格式

//数据模型
class TypeBeen : NSObject {
    var text: String?
    var select: Bool?
}
  //准备数据
    var typeArray:Array<TypeBeen> = []
   let typeBeen1 = TypeBeen()
   typeBeen1.text = "Popular"
   typeBeen1.select = true
   let typeBeen2 = TypeBeen()
   typeBeen2.text = "Love"
   typeBeen2.select = false
//点击对数据进行修改刷新
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if(collectionView == TypeCaptionFrameCollectionView){
            for i in 0...(typeArray.endIndex - 1) {
                typeArray[i].select = false
            }
            typeArray[indexPath.row].select = true
            //数据刷新
            TypeCaptionFrameCollectionView.reloadData()
        }
    }

注:CollectionView列表刷新数据reloadData

相关文章

网友评论

      本文标题:CollectionView基础动态列表

      本文链接:https://www.haomeiwen.com/subject/hmtivltx.html