Using the GestureRecognizer attached to a view triggers my app to crash with EXC_BAD_ACCESS error. Here’s the classes involved
• BoardViewController – Displaying a board (as background) set as rootViewController in the AppDelegate. It instantiates multiple objects of the “TaskViewcontroller”.
//BoardViewController.h
@interface BoardViewController : UIViewController {
NSMutableArray* allTaskViews; //for storing taskViews to avoid having them autoreleased
}
//BoardViewController.m - Rootviewcontroller, instantiating TaskViews
- (void)viewDidLoad
{
[super viewDidLoad];
TaskViewController* taskA = [[TaskViewController alloc]init];
[allTaskViews addObject:taskA];
[[self view]addSubview:[taskA view]];
}
• TaskViewController – An indivual box displayed on the board. It should be draggable. Therefore I attached UIPanGestureRecoginzer to its view
- (void)viewDidLoad
{
[super viewDidLoad];
UIPanGestureRecognizer* panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[[self view] addGestureRecognizer:panRecognizer];
}
- (void)handlePan:(UIPanGestureRecognizer *)recognizer {
NSLog(@"PAN!");
}
The .xib file is a simple view.

All programming with the gesture recognizer I’d prefer to do in code. Any idea how to fix the error causing the app crash?
The method
handlePanis on your view controller, not on your view. You should set the target toself:EDIT (in response to the edit of the question) As omz has correctly noted, your
TaskViewControllergets released uponBoardViewController‘sviewDidLoad:exit. There are two ways of dealing with it:handlePanmethod into the parent view controller, along with the code ofviewDidLoad:, orTaskViewController *taskA, rather than making it a local variable.