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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容