我有一个来自UIViewController的派生类,名为AdminViewController。
我想为此视图启用singleTab识别器。
ViewView在MainViewController中调用:
AdminViewController* AdminViewC = [[AdminViewController alloc]init];
[self.view addSubview:AdminViewC.view];
在AdminViewController.m
中- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
if([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]])
{
[gestureRecognizer addTarget:self action:@selector(tappedGestureAction:)];
}
return YES;
}
-(void)tappedGestureAction:(UITapGestureRecognizer *)tap{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"View Tapped" message:@"Tapped" delegate:nil cancelButtonTitle:@"Dissmiss" otherButtonTitles:@"Done", nil];
[av show];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.view setFrame:CGRectMake(500, -200, 200, 300)];
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self.view action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleFingerTap];
}
如果我触摸MainViewController中的View,我会得到:
' NSInvalidArgumentException',原因:' - [UIView handleSingleTap:]:无法识别的选择器发送到实例0x296d50'
有人提示吗? 问候,菲尔
答案 0 :(得分:1)
您已在self.view
添加了手势,但未实现单击选择器:
-(void)handleSingleTap:(UITapGestureRecognizer*)tapGesture
{
}