How to check for specific events in method touchesBegan:withEvent:

306 views Asked by At

How can I add a check in the method below so that the method will only respond to the event "UIControlEventTouchUpInside"?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}

Can I check the event? Like

if (event == UIControlEventTouchUpInside)
{
    //Do something
}

The above code does not work. Any advise how I can check for specific events in this method?

2

There are 2 answers

0
Martin Wickman On

If you want to use events like touch-up-inside, you shouldn't need to bother with low-level touch handling. Instead use addTarget like this:

[button addTarget:self action:@selector(myMethod:) forControlEvents:UIControlEventTouchUpInside];
0
Sudesh Kumar On
Assigned tag value for that view or control, where you want to finding touch. And write this code inside touch method:
UITouch *touch = [touches anyObject];
int tagValue =[touch view].tag;

if(tagValue == <YOUR TAG VALUE>){
//perform your action
}