Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newlearner

macrumors member
Original poster
Jul 30, 2009
37
0
india
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
 
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];
 
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.
 
@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
 

Attachments

  • errortrace.png
    errortrace.png
    112.8 KB · Views: 129
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.