Reputation: 61
I have a problem with tap gesture, I have a view controller and on top of the view controller am adding the UILABEL dynamically and adding tap gesture to the label. When Tap on the Uilabel it is crashing.
[ViewController singleTap:]: unrecognized selector sent to instance :- Crash report
Below is the piece of the code
- (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");
}
Upvotes: 0
Views: 175