iphone - Getting index in NSMutableArray of selected or tapped image -


i developing app add images nsmutablearray , display them in image view.

my problem don't know how index of selected or tapped image in app.

frontscards=[[nsmutablearray alloc]initwithobjects:@"cloub1.png",@"cloub2.png",@"cloub3.png",@"cloub4.png", nil];  for(int m=0; m< [frontscards count];m++) {     nsstring *imagename=[frontscards objectatindex:m];      nsstring *fullimagename=[nsstring stringwithformat:@"%@",imagename];      int padding=25;      cgrect imageviewframe=cgrectmake(scrollview.frame.size.width*m+padding, scrollview.frame.origin.y, scrollview.frame.size.width-2*padding, scrollview.frame.size.height);      imgview=[[uiimageview alloc]initwithframe:imageviewframe];      [imgview setimage:[uiimage imagenamed:fullimagename]];      [imgview setcontentmode:uiviewcontentmodescaleaspectfill];       [scrollview addsubview:imgview];       uitapgesturerecognizer *doubletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(doubletapimgview:)];     doubletap.numberoftapsrequired = 2;     doubletap.delegate = self;      [self.imgview addgesturerecognizer:doubletap];      self.imgview.userinteractionenabled=yes;     }   cgsize scrollviewsize=cgsizemake(scrollview.frame.size.width*[frontscards count], scrollview.frame.size.height); [scrollview setcontentsize:scrollviewsize]; [self.view addsubview:scrollview]; 

what should in tap gesture recognizer index of image?

- (void)doubletapimgview:(uitapgesturerecognizer *)gesture {      nslog(@"double-tap"); } 

maybe can use this:

first add name of image accessibilityidentifier of the imageview [imgview setaccessibilityidentifier:imagename]; 

then in taprecognizer:

-(void)doubletapimgview:(uitapgesturerecognizer *)gesture{     uiimageview *imgview = (uiimageview *)gesture.view;      int idx = [frontcards indexofobject:[imgview accessibilityidentifier]]; } 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -