我创建了一个标签,然后在上面设置的点击,但是点击之后报错
.h文件:
@interface ViewController : UIViewController
{
UILabel *alabel;
}
@property (strong, nonatomic) UILabel *alabel;
.m文件:
- (void)viewDidLoad
{
[super viewDidLoad];
alabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
alabel.text = @"Drag me!";
alabel.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)];
[alabel addGestureRecognizer:tapGesture];
[self.view addSubview:alabel];
}
- (void)labelTap:(UITapGestureRecognizer *)tapGesture {
TouchLabelViewController *touchLabelViewController = [[TouchLabelViewController alloc] initWithNibName:@"TouchLabelViewController" bundle:[NSBundle mainBundle]];
[self presentModalViewController:touchLabelViewController animated:NO];
}
日志显示:
2012-10-29 11:19:17.313 DragableControll[795:f803] -[ViewController labelTap]: unrecognized selector sent to instance 0x68956b0
2012-10-29 11:19:17.316 DragableControll[795:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController labelTap]: unrecognized selector sent to instance 0x68956b0'
lz把Selector加错了
UITapGestureRecognizer *tapGesture =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)];
``
应该改为:
UITapGestureRecognizer *tapGesture =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap:)];
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。