UICollectionView详解:3-代理协议:点击Cell

通过CollectionView的代理协议,可以监控用户点击集合视图中的单元格,在代理协议中,可以进行进一步处理,如:跳转控制器等等。

集合视图代理协议:点击Cell

点击单元格

-(void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{

NSLog(@"%s",__func__);

//获取点击的单元格

MYCollectionCell*cell=(MYCollectionCell*)[self.collectionView cellForItemAtIndexPath:indexPath];

cell.backgroundColor=[UIColorredColor];

}

取消选中单元格

-(void)collectionView:(UICollectionView*)collectionView didDeselectItemAtIndexPath:(NSIndexPath*)indexPath{

//获取点击的单元格

MYCollectionCell*cell=(MYCollectionCell*)[self.collectionView cellForItemAtIndexPath:indexPath];

cell.backgroundColor=[UIColororangeColor];

}

是否支持多选

@property(nonatomic)BOOL allowsMultipleSelection;// 默认为NO

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容