0

我正在尝试在我的 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)

有人有想法吗?

4

1 回答 1

0

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

与分配或委托方法有关!

于 2014-09-23T18:48:59.673 回答