Detect Tap on UIImageView within UITableViewCell

前端 未结 6 1556
无人及你
无人及你 2021-02-20 11:40

I have a custom complex UITableViewCell where there are many views. I have an UIImageView within it which is visible for a specific condition. When it\'s visible ,

6条回答
  •  南旧
    南旧 (楼主)
    2021-02-20 12:32

    A gesture recognizer will only pass one argument into an action selector: itself. So u need to pass the uid value alone.Like this.

    Guessing this lies within the cellForRowAtIndexPath: method

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        //code
        cell.AddContactImage.hidden = NO ;
        cell.imageView.userInteractionEnabled = YES;
        cell_Index=indexPath.row ;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self               action:@selector(onTapContactAdd:)];   //just one arguement passed
        [tap setNumberOfTouchesRequired:1];
        [tap setNumberOfTapsRequired:1];
        [tap setDelegate:self];
        [cell.AddContactImage addGestureRecognizer:tap];
        //rest of code
    }
    
    -(void)onTapContactAdd :(NSString*) uid
    {
         NSLog(@"Tapped");
         CustomCell *cell=(CustomCell *)[yourtableView cellForRowAtIndexPath:[NSIndexPath  indexPathForRow:cell_Index inSection:0]]; 
         //cell.AddContactImage will give you the respective image .
         // Do something with uid from parameter .
    }
    

    So here when you tap on the visible image in the respective custom cell,the onTapContactAdd: method gets called with the corresponding uid value(parameter) and now we have the cell.AddContactImage also accessible which i believe is why you were trying to pass it also along with the parameters . Hope it Helps!!!

提交回复
热议问题