美文网首页
UICollectionView详解:3-代理协议:点击Cell

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

作者: 赵亦晨 | 来源:发表于2016-11-08 16:33 被阅读0次

通过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

相关文章

网友评论

      本文标题:UICollectionView详解:3-代理协议:点击Cell

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