Reproduced in: http://www.pocketdigi.com/20140218/1276.html
Uiimageview is not like UIButton, click on the mouse can be linked to the event, and unlike Android has Onclicklistener, here need to rely on the UITapGestureRecognizer class. As you can see from the class name, this class is used to handle tap (click) events.
The BBC and voaspecial are Uiimageview objects.
[BBC Setuserinteractionenabled:yes]; [Voaspecial Setuserinteractionenabled:yes]; [BBC Addgesturerecognizer:[[uitapgesturerecognizer alloc] initwithtarget:self action: @selector (clickcategory:)]; [Voaspecial Addgesturerecognizer:[[uitapgesturerecognizer alloc] initwithtarget:self action: @selector ( Clickcategory:)];
It has been tested that multiple Uiimageview cannot share a UITapGestureRecognizer object, which was previously called without effect.
Click on the view to determine who clicked from.
-(void) Clickcategory: (UITapGestureRecognizer *) gesturerecognizer{NSLog (@"Click"); NSLog (@"%HHD", [Gesturerecognizer Ismemberofclass:[uitapgesturerecognizerclass]]); UIView*viewclicked=[Gesturerecognizer view]; if(viewclicked==BBC) {NSLog (@"BBC"); }Else if(viewclicked==voaspecial) {NSLog (@"voaspecial"); } }
iOS Development: Add Click events for Uiimageview