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;

}

转载于:https://www.cnblogs.com/bacon698/p/5065400.html

你可能感兴趣的:(iOS CollectionView交互,CollectionViewCell点击操作)