UITapGestureRecognizer访问不当

时间:2013-05-16 15:49:15

标签: ios uiview uitapgesturerecognizer

我正在尝试在我的UIView上添加UITapGestureRecognizer。这是我的UIViewController代码的一部分。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    // Create and initialize a tap gesture
    UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(respondToTapGesture:)];

    // Specify that the gesture must be a single tap
    tapRecognizer.numberOfTapsRequired = 1;

    // Add the tap gesture recognizer to the view
    [self.view addGestureRecognizer:tapRecognizer];

}

-(void) respondToTapGesture:(UITapGestureRecognizer *)gr {
    NSLog(@"It's working !");
}

问题在于,当我点击视图时,我收到此消息:

0x396e25d0:  ldr    r3, [r4, #8]      < Thread 1 : EXC_BAD_ACCESS (code=1, address=0x8)

有没有人有想法?

1 个答案:

答案 0 :(得分:0)

此错误的一个可能性是,如果您在模态视图或类似的东西上执行此操作并且它已经解除锁定。在返回/解除具有uiGestureRecognizer的viewcontroller之前,请务必从self.view.window中删除手势识别器。

与分配或委托方法有关!