problems in implementing Gesture Recognizers for iPad app

Discussion in 'iPhone/iPad Programming' started by newlearner, May 11, 2011.

  1. macrumors member



    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:

        UITapGestureRecognizer *recognizer;
        recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandler:)];
        [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
  2. macrumors 65816


    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.
  3. macrumors member


    @ jnoxx : tried that too...but it doesnt make any difference
  4. macrumors member

    This is what I did and it works. What's the error?

            UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
            swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
            [self.view addGestureRecognizer:swipeLeft];
            [swipeLeft release];
    	UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
     	[self.view addGestureRecognizer:singleTap]; 
            [singleTap release];
  5. macrumors regular

    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.
  6. macrumors 68030


    @OP, what does crash mean? What do you see in the debugger console?
  7. macrumors member


    @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

    Attached Files:

  8. macrumors 68030


    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

Share This Page