0

我有一个来自 UIViewController 的派生类,名为 AdminViewController。

我想为此视图启用 singleTab 识别器。

在 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 中触摸视图,我会得到:

'NSInvalidArgumentException',原因:'-[UIView handleSingleTap:]:无法识别的选择器发送到实例 0x296d50'

有人提示吗?问候,菲尔

4

1 回答 1

1

您已在 上添加手势self.view,但未实现单击选择器:

-(void)handleSingleTap:(UITapGestureRecognizer*)tapGesture
{
}
于 2012-11-27T20:13:48.857 回答