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