Detect Tap on UIImageView within UITableViewCell

前端 未结 6 1535
无人及你
无人及你 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:40

    Add the gesture recognizer to the cell itself.

    Then in the action selector, do as following to know which view has been tapped:

    -(IBAction)cellTapped:(UITapGestureRecognizer*)tap
    {
        MyCustomTableViewCell* cell = tap.view;
        CGPoint point = [tap locationInView:cell.contentView];
        UIView* tappedView = [cell.contentView hitTest:point withEvent:NULL];
    
        if (tappedView==cell.myImageView) {
            // Do whatever you want here,
        }
        else { } // maybe you have to handle some other views here
    }
    

提交回复
热议问题