我有点击手势的问题,我有一个视图控制器,在视图控制器的顶部动态添加 UILABEL 并将点击手势添加到标签。当点击 Uilabel 时,它会崩溃。
[ViewController singleTap:]:发送到实例的无法识别的选择器:- 崩溃报告
下面是一段代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 150, 35)];
label.userInteractionEnabled = YES;
label.backgroundColor = [UIColor greenColor];
label.text = @"label";
label.textAlignment = NSTextAlignmentCenter;
UITapGestureRecognizer * single = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
[label addGestureRecognizer:single];
single.numberOfTapsRequired = 1;
[single release];
[self.view addSubview:label];
}
-(void) singletap:(id)sender
{
NSLog(@"single tap");
}