2011-10-14 34 views
0

如何在下面的方法中添加檢查,以便該方法僅響應事件「UIControlEventTouchUpInside」?如何檢查方法touchesBegan中的特定事件:withEvent:

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

我可以檢查事件嗎?像

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

上述代碼不起作用。任何建議如何檢查此方法中的特定事件?

回答

1
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 
} 
1

如果你要使用像觸摸式,裏面的事件,你不應該需要低級別的觸摸操作打擾。相反使用addTarget像這樣:

[button addTarget:self action:@selector(myMethod:) forControlEvents:UIControlEventTouchUpInside]; 
相關問題