iOS CollectionView交互,CollectionViewCell点击操作

简单方法

- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //写所需实现的代码
}

还有一个作死方法,在生成cell的时候添加Target

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
-     cell.tag = indexPath.row;

    cell.userInteractionEnabled = YES;

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(editing)];

    [cell addGestureRecognizer:tap];

    return cell;

}
posted @ 2015-12-16 03:55  嘣嚓嚓  阅读(487)  评论(0编辑  收藏  举报