ios - indexPathForSelectedRow returning wrong index -


i want of data of displayed in cell when i'm tapping on button placed in cell. have implemented used indexpathforselectedrow method. when i'm tapping on cell, method returning 0 index, if i'm not tapping on 0th index cell. code used button -

- (ibaction)datasavelounge:(id)sender {  nsindexpath *path = [self.loungetable indexpathforselectedrow];  nsstring *titlesave = [[loungedata objectatindex:path.row] valueforkey:@"title"];  nsstring *subtitlesave = [[loungedata objectatindex:path.row] valueforkey:@"excerpt"];  nsstring *idsave = [[loungedata objectatindex:path.row] valueforkey:@"id"];   savemdl = [favouritesmodel savefavourites:titlesave and:subtitlesave and:idsave];  } 

edit : added cellfforrowatindex method

-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{  static nsstring *loungecellid = @"mycelllounge"; loungetablecell *loungecell = [tableview dequeuereusablecellwithidentifier:loungecellid];  if (loungecell == nil) {      loungecell = [[loungetablecell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"mycelllounge"]; }  loungecell.loungetitle.text = [[loungedata objectatindex:indexpath.row]valueforkey:@"title"]; loungecell.loungesubtitle.text = [[loungedata objectatindex:indexpath.row]valueforkey:@"excerpt"];  dispatch_async(dispatch_get_main_queue(), ^{      loungecell.loungeimgview.backgroundcolor = [uicolor colorwithpatternimage:[uiimage imagenamed:@"default"]];      [loungecell.loungeimgview sd_setimagewithurl:[nsurl urlwithstring:[[loungedata objectatindex:indexpath.row] valueforkey:@"banner_image"]]]; });  return  loungecell; } 

i'm saving data in core data on button click, hence last method call

try if clicking button in row set button tag

cell.button.tag = indexpath.row  [cell.button addtarget:self action:@selector(datasavelounge:) forcontrolevents:uicontroleventtouchupinside]; 

in cellforrowatindexpath

- (ibaction)datasavelounge:(id)sender { uibutton *pressedbutton = (uibutton *)sender;    nslog(@"tag of button pressed:%d",pressedbutton.tag); } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -