iphone - Detect UIImageView click in UITableViewCell -


i have make call specific number when imageview clicked in tableviewcell.the number call made displayed in label beside imageview.but couldn't cell clicked.always referring last cell.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath  {      if(cell == nil)     {         cell =[[uitableviewcell alloc]initwithstyle:uitableviewcellstyledefault  reuseidentifier:cellidentifier];         lblphone = [[uilabel alloc] initwithframe:cgrectzero];         lblphone.tag = 116;         lblphone.backgroundcolor = [uicolor clearcolor];         [lblphone setfont:[uifont fontwithname:@"helvetica" size:12]];         [lblphone setlinebreakmode:uilinebreakmodewordwrap];         [lblphone setuserinteractionenabled:yes];          uitapgesturerecognizer *tapgesturerecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(labelbutton:)];         tapgesturerecognizer.cancelstouchesinview=no;         [tapgesturerecognizer setnumberoftapsrequired:1];         [lblphone addgesturerecognizer:tapgesturerecognizer];         [tapgesturerecognizer release];         [cell addsubview:lblphone];          myimageview = [[uiimageview alloc] initwithframe:cgrectzero];         myimageview.tag = 120;         myimageview.image=[uiimage imagenamed:@"callimg.png"];          uitapgesturerecognizer *tapped = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(imageselectedintable:)];         [tapped setnumberoftapsrequired:1];         [myimageview addgesturerecognizer:tapped];         [tapped release];         [cell addsubview:myimageview];     }      [myimageview setframe:cgrectmake(10, 50,30,30)];     myimageview= (uiimageview*)[cell viewwithtag:120];     myimageview.image=[uiimage imagenamed:@"callimg.png"];     myimageview.userinteractionenabled=yes;      cgsize constraint5 = cgsizemake(320, 2000.0f);     cgsize size5=[phone sizewithfont:[uifont fontwithname:@"helvetica" size:14] constrainedtosize:constraint5 linebreakmode:uilinebreakmodewordwrap];     lblphone =(uilabel *)[cell viewwithtag:116];     [lblphone setframe:cgrectmake(45,name.frame.size.height+name.frame.origin.y,320, size5.height)];     lblphone.textalignment=uitextalignmentleft;     lblphone.backgroundcolor=[uicolor clearcolor];     lblphone.text=[nsstring stringwithformat:@"%@ ",phone ];     [lblphone sizetofit]; } 

and in tapgesture of imageclick writing :

-(ibaction)imageselectedintable:(uitapgesturerecognizer*)gesture {     uiimageview *imgview = (uiimageview *) [gesture view];     uitableviewcell *cell = (uitableviewcell*)[[imgview superview]superview];     nsindexpath *tappedindexpath = [self.tableview indexpathforcell:cell];     nslog(@"image tap %@", tappedindexpath);     uilabel *phoneno = (uilabel *)[cell viewwithtag:116];      nsstring *phonenumber = [@"telprompt://" stringbyappendingstring:phoneno.text];     [[uiapplication sharedapplication] openurl:[nsurl urlwithstring:phonenumber]]; } 

but referncing last cell clicked irrespective of cell clicked.couldn't understand im going wrong ?

i see try access cell,

uitableviewcell *cell = (uitableviewcell*)[[imgview superview]superview]; 

but add image view to

[cell addsubview:myimageview]; 

you should adding image view cell.contentview.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -