PDA

View Full Version : problems in implementing Gesture Recognizers for iPad app




newlearner
May 11, 2011, 02:51 AM
hello,

i am working with gesture recognizers in my app. The app crashes whenever there is any gesture - tap or swipe. here is my code for detecting tap:



-(void)viewDidLoad{
UITapGestureRecognizer *recognizer;

recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandler:)];
recognizer.numberOfTapsRequired=1;

recognizer.numberOfTouchesRequired=1;
[self.view addGestureRecognizer:recognizer];
[recognizer release];
[super viewDidLoad];
}

- (void) tapHandler: (UITapGestureRecognizer *)gesture {
NSLog(@"Tap ...");
}



The app being written is for iPad using iOS 4.3.2

can anyone point out where the problem is...

many thanks



jnoxx
May 11, 2011, 03:16 AM
not sure, haven't been working with recognizers alot. but u are releasing it, before you're using it. try commenting out the release, and check it out.

newlearner
May 11, 2011, 03:44 AM
@ jnoxx : tried that too...but it doesnt make any difference

Alphaforcex
May 17, 2011, 07:35 PM
This is what I did and it works. What's the error?


//Swipe
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
[swipeLeft release];

//Tap
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleTap];
[singleTap release];

Sykte
May 17, 2011, 10:20 PM
not sure, haven't been working with recognizers alot. but u are releasing it, before you're using it. try commenting out the release, and check it out.

Actually he isn't, sorry typing on the iPad otherwise I would explain why. You should post any errors you receive this will help other developers help you.

PhoneyDeveloper
May 17, 2011, 10:55 PM
@OP, what does crash mean? What do you see in the debugger console?

newlearner
May 17, 2011, 11:51 PM
@Alphaforcex: Your code doesnt work for me though. On which OS version are you implementing it?

@PhoneyDeveloper: The program simply hangs up with an objc_msgSend error. Please find attached the screenshot of the stack trace

PhoneyDeveloper
May 18, 2011, 07:18 AM
Crashes in objc_MsgSend are caused by sending a message to a dealloced object. I can't tell why that would happen in your case. The object being messaged is presumably your view controller. Is it possible that the view outlives the view controller? You can turn on NSZombies to debug this further. And you can search the forum and google for objc_MsgSend. It's a very common problem.

You can start here

http://www.sealiesoftware.com/blog/archive/2008/09/22/objc_explain_So_you_crashed_in_objc_msgSend.html