[UITapGestureRecognizer tag]: unrecognized selector sent to instance

前端 未结 5 1422
一个人的身影
一个人的身影 2020-12-16 00:44

I am having a series of imageview arranged, and assigning a TapView recognizer to it

UITapGestureRecognizer *tapRecognizer = [[UITa         


        
5条回答
  •  粉色の甜心
    2020-12-16 01:20

    You can use this..

    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc]
                                             initWithTarget:self action:@selector(action:)];
    [tapRecognizer setNumberOfTouchesRequired:1];
    [tapRecognizer setDelegate:self];
    imageView.userInteractionEnabled = YES;
    imageView.tag = 1111;
    [imageView addGestureRecognizer:tapRecognizer];
    

    And in action try this..

    -(void) action:(id)sender
      {
        NSLog(@"TESTING TAP");
        UITapGestureRecognizer *tapRecognizer = (UITapGestureRecognizer *)sender;
        NSLog (@"%d",[tapRecognizer.view tag]);
      }
    

    Explaination:

    UITapGestureRecognizer has not property like tag. but it has property view, from this property you can access the view with which UITapGestureRecognizer was attached.

    Hope it will help you

提交回复
热议问题