Ios UIGestureRecognitor在UIImageView上工作不正常

Ios UIGestureRecognitor在UIImageView上工作不正常,ios,objective-c,iphone,uitableview,uiimageview,Ios,Objective C,Iphone,Uitableview,Uiimageview,导言:- 在我的项目中,我正在自定义TableViewCellvideoTableViewCell.h中包含的UIImageView上使用UIAPTgestureRecognitizer。我添加了一个点击手势和长按手势来执行一些动作。看了之后 我启用了userInteraction.com,但收到了cell.image2_2和cell.image1_1的响应。 问题:-但cell.image1_2在点击手势或长按手势时没有响应。 注:image1_2和image2_2位于一个小区复用标识符2中,

导言:- 在我的项目中,我正在自定义TableViewCellvideoTableViewCell.h中包含的UIImageView上使用UIAPTgestureRecognitizer。我添加了一个点击手势和长按手势来执行一些动作。看了之后 我启用了userInteraction.com,但收到了cell.image2_2和cell.image1_1的响应。 问题:-但cell.image1_2在点击手势或长按手势时没有响应。 注:image1_2和image2_2位于一个小区复用标识符2中,image1_1位于另一个小区复用标识符中 宏

videoViewController.m ->UITableView数据源方法

videoTableViewCell.m


如果有人需要更多信息,就问我。顺便说一句,谢谢你的关注。

所以我终于明白了重点。 问题是我正在创建一个UIAPTgestureRecognitor和UILongPressgestureRecognitor对象,并在多个对象上使用它

所以,这里有一个解决方案。。 对每个对象使用新的UIgestureRecognitor,如下图:

  RADIOUS 16.0
  TITLE_COLOR [UIColor colorWithRed:102.0/255.0 green:255.0/255.0 blue:0/255.0 alpha:1]
-(void)tableView:(UITableView *)tableView willDisplayCell:(videoTableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Action:)];
    tapGesture.numberOfTapsRequired = 1;
    UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
    if(indexPath.row%2 == 0){//cell with two boxes
        NSArray* array = [newArray objectAtIndex:indexPath.row];
        if(array.count > 1){//WHEN CONATAINS TWO OBJECTS in Array
            NSString* string = [array objectAtIndex:0];
            if(string){
                cell.image1_2.hidden = NO;
            }else{
                cell.image1_2.hidden = YES;
            }
            [cell.image1_2 setImage:[self getThumbNailByName:string]];
            NSString*tag = [NSString stringWithFormat:@"%ld%ld",indexPath.row,(long)0];
            cell.image1_2.tag = [tag integerValue];
            [cell.image1_2 addGestureRecognizer:tapGesture];
            if(selectionEnabled){
                if([selectedItems containsObject:[NSNumber numberWithInteger:[tag integerValue]]]){
                    cell.image1_2.layer.borderWidth = 1.0;
                    cell.image1_2.layer.borderColor = TITLE_COLOR.CGColor;
                }else{
                    cell.image1_2.layer.borderColor = [UIColor clearColor].CGColor;
                    cell.image1_2.layer.borderWidth = 0;
                }
            }else{
                [cell.image1_2 addGestureRecognizer:longPress];
            }

            string = [array objectAtIndex:1];
            if(string){
                cell.image2_2.hidden = NO;
            }else{
                cell.image2_2.hidden = YES;
            }
            [cell.image2_2 setImage:[self getThumbNailByName:string]];
            tag = [NSString stringWithFormat:@"%ld%ld",indexPath.row,(long)1];
            cell.image2_2.tag = [tag integerValue];
            [cell.image2_2 addGestureRecognizer:tapGesture];
            if(selectionEnabled){
                if([selectedItems containsObject:[NSNumber numberWithInteger:[tag integerValue]]]){
                    cell.image2_2.layer.borderWidth = 1.0;
                    cell.image2_2.layer.borderColor = TITLE_COLOR.CGColor;
                }else{
                    cell.image2_2.layer.borderColor = [UIColor clearColor].CGColor;
                    cell.image2_2.layer.borderWidth = 0;
                }
            }else{
               [cell.image2_2 addGestureRecognizer:longPress];
            }
        }else{// WHEN CONATAINS ONLY ONE OBJECT in Array
            NSString* string = [array objectAtIndex:0];
            if(string){
                cell.image1_2.hidden = NO;
            }else{
                cell.image1_2.hidden = YES;
            }
            NSString*tag = [NSString stringWithFormat:@"%ld%ld",indexPath.row,(long)0];
            cell.image1_2.tag = [tag integerValue];
            [cell.image1_2 addGestureRecognizer:tapGesture];
            cell.image2_2.hidden = YES;
            if(selectionEnabled){
                if([selectedItems containsObject:[NSNumber numberWithInteger:[tag integerValue]]]){
                    cell.image1_2.layer.borderWidth = 1.0;
                    cell.image1_2.layer.borderColor = TITLE_COLOR.CGColor;
                }else{
                    cell.image1_2.layer.borderColor = [UIColor clearColor].CGColor;
                    cell.image1_2.layer.borderWidth = 0;
                }
            }else{
                [cell.image1_2 addGestureRecognizer:longPress];
            }
        }
    }else{//cell with one box
        NSString* string = [[newArray objectAtIndex:indexPath.row] objectAtIndex:0];
        if(string){
            cell.image1_1.hidden = NO;
        }else{
            cell.image1_1.hidden = YES;
        }
        [cell.image1_1 setImage:[self getThumbNailByName:string]];
        NSString*tag = [NSString stringWithFormat:@"%ld%ld",indexPath.row,(long)0];
        cell.image1_1.tag = [tag integerValue];
        [cell.image1_1 addGestureRecognizer:tapGesture];
        if(selectionEnabled){
            if([selectedItems containsObject:[NSNumber numberWithInteger:[tag integerValue]]]){
                cell.image1_1.layer.borderWidth = 1.0;
                cell.image1_1.layer.borderColor = TITLE_COLOR.CGColor;
            }else{
                cell.image1_1.layer.borderColor = [UIColor clearColor].CGColor;
                cell.image1_1.layer.borderWidth = 0;
            }
        }else{
            [cell.image1_1 addGestureRecognizer:longPress];
        }
    }
}
- (void)awakeFromNib
{
    // Initialization code
    [image1_1 setUserInteractionEnabled:YES];
    [image1_2 setUserInteractionEnabled:YES];
    [image2_2 setUserInteractionEnabled:YES];
    if([self.reuseIdentifier isEqualToString:@"one"]){
        image1_1.layer.cornerRadius = RADIOUS;
        image1_1.clipsToBounds = YES;
    }else{
        //Two Album Cell'cell2'
        image1_2.layer.cornerRadius = RADIOUS;
        image1_2.clipsToBounds = YES;
        image2_2.layer.cornerRadius = RADIOUS;
        image2_2.clipsToBounds = YES;
    }
}
UITapGestureRecognizer* tapGesture1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Action:)];
    tapGesture1.numberOfTapsRequired = 1; 
[cell.image1_1 addGestureRecognizer:tapGesture1];

UITapGestureRecognizer* tapGesture2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Action:)];
    tapGesture2.numberOfTapsRequired = 1; 
[cell.image1_2 addGestureRecognizer:tapGesture2];

UITapGestureRecognizer* tapGesture3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Action:)];
        tapGesture3.numberOfTapsRequired = 1; 
    [cell.image2_2 addGestureRecognizer:tapGesture3];
//do same for UILogPressGestureRecognizer