problems in implementing Gesture Recognizers for iPad app

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

  1. macrumors member

    newlearner

    Joined:
    Jul 30, 2009
    Location:
    india
    #1
    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:

    Code:
    
    -(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
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    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. thread starter macrumors member

    newlearner

    Joined:
    Jul 30, 2009
    Location:
    india
    #3
    @ jnoxx : tried that too...but it doesnt make any difference
     
  4. macrumors member

    Joined:
    Jun 23, 2010
    #4
    This is what I did and it works. What's the error?

    Code:
            
    //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];
    
     
  5. macrumors regular

    Joined:
    Aug 26, 2010
    #5
    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

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    @OP, what does crash mean? What do you see in the debugger console?
     
  7. thread starter macrumors member

    newlearner

    Joined:
    Jul 30, 2009
    Location:
    india
    #7
    @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

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    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/...c_explain_So_you_crashed_in_objc_msgSend.html
     

Share This Page