0

我在“[subview touchesBegan:touches withEvent:event];”这一行得到一个 EXC_BAD_ACCESS。当我删除那条线时,一切正常。我做错了什么?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for(UIView *subview in [self.view subviews]) {
        NSLog(@"%@", subview);
        NSLog(@"%@", touches);
        NSLog(@"%@", event);
        [subview touchesBegan:touches withEvent:event];
    }
}
4

2 回答 2

2

没有回溯,很难说。

但是,touchesBegan:withEvent:这不是您应该从代码中调用的方法。它只能由系统调用。

更有可能的是,您在无法处理它的子视图上调用该方法,因此它调用它将它传递给它的superview......然后,无限循环繁荣。

于 2013-07-10T01:03:29.010 回答
-2

You can not call the "touchesBegan:touches withEvent:event" directly, it's a delegate method in iOS which call by system. If you want to send the touch event to subview, why dont you define a method like "touchesBegan:",do you want to do in touchesBegan, and call it in like this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for(UIView *subview in [self.view subviews]) { NSLog(@"%@", subview); NSLog(@"%@", touches); NSLog(@"%@", event); [subview touchesBegan]; } }

于 2013-07-10T03:00:52.027 回答