iOS UICollectionViewCell点击无响应的解决方法

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString * cellId = @"Cell";

    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];

    

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

    [cell.contentView addGestureRecognizer:tap];

    

    return cell;

}


-(void)tapAction:(UITapGestureRecognizer *)tap

{

    CGPoint point = [tap locationInView:self.collection];

    NSIndexPath * indexPath = [self.collection indexPathForItemAtPoint:point];

    NSLog(@"==============%ld--------------%ld",(long)indexPath.section,(long)indexPath.row);

}

你可能感兴趣的:(iOS)