ios - recognize the different view tag via UITapGestureRecognizer -


i use code below add touch tapgesturerecognizer on 3 views.

uitapgesturerecognizer *anuitapgesturerecognizer = [[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(dosomething:)];  view1.tag=1; [view1 addgesturerecognizer:anuitapgesturerecognizer];  view2.tag=2; [view2 addgesturerecognizer:anuitapgesturerecognizer];  //...  view3.tag=3; [view3 addgesturerecognizer:anuitapgesturerecognizer]; 

same as

enter image description here

but if tap view1, view2, view3, code below output 1, 2, 3

- (void)dosomething:(uitapgesturerecognizer *)tap {      nsstring *s= [nsstring stringwithformat:@"%ld", (long)tap.view.tag];      nslog(@"%@",s);  } 

s returns 3

your comment welcome

you can't this .you need make different uitapgesturerecognizer instances each uiview's.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -