UITapGestureRecognizer tag的问题

在我们的界面上可能有很多的UILabel需要设置点击事件,所以我们给他们添加了手势操作,用tag 去判断点击的是哪个控件,而已报出以下错误:

[UITapGestureRecognizer tag]: unrecognized selector sent to instance

解决方法:

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

 

 

-(void) action:(id)sender
  {
    NSLog(@"TESTING TAP");
    UITapGestureRecognizer *tapRecognizer = (UITapGestureRecognizer *)sender;
    NSLog (@"%d",[tapRecognizer.view tag]);
  }
评论 (2)
  1. avatar
    沙发
    苟保罗 2016-07-28 06:36

    写的这都是什么语言啊,看不懂呢