objective c - When didDeselect a Custom Cell the image doesn't change on iOS -


im working uitableview has custom cell. custom cell has label , uiimage, uiimage used checkbox.

so problem once click row checkbox image changes checkmark png image (which ok) once click same row again doesnt diselect row, function diddeselectrowatindexpath runs , set nslogs check on image not changed uncheckbox , background color doesnt change.

i feel because tableview not been refreshed

the funny thing here if dont use custom cell , use accessorytype none or checkmark (depending case) works.

here code viewdidload init variable:

-(void)viewdidload  {     [super viewdidload];      //let me select more 1 row     self.tableview.allowsmultipleselection = yes;  //used store cells selected       self.selectedindexpaths = [[nsmutablearray alloc] init];  } 

i got 1 section , 20 rows (later going array thats no problem)

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     customecell *cell = [tableview dequeuereusablecellwithidentifier:@"cell" forindexpath:indexpath];      if(cell == nil)     {         cell = [[customecell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"cell"];     }       cell.cellnamedrinklabel.text = @"cell";      if ( [self.selectedindexpaths indexofobject:indexpath] == nsnotfound )     {          cell.cellcheckboximageview.image = [uiimage imagenamed:[nsstring stringwithformat:@"uncheckbox.png"]];      } else     {         cell.cellcheckboximageview.image = [uiimage imagenamed:[nsstring stringwithformat:@"checkbox.png"]];      }        return cell; } 

here didselectrowatindexpath function:

-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     customecell *cell = [tableview dequeuereusablecellwithidentifier:@"cell" forindexpath:indexpath];     cell.cellcheckboximageview.image = [uiimage imagenamed:[nsstring stringwithformat:@"checkbox.png"]];       if(![self.selectedindexpaths containsobject:indexpath])     {         [self.selectedindexpaths addobject:indexpath];     }      nslog(@"%ld", (long)indexpath.row);  } 

and here diddeselectrowatindexpath function (the 1 feel problem)

- (void)tableview:(uitableview *)tableview diddeselectrowatindexpath:(nsindexpath *)indexpath {     customecell *cell = [tableview dequeuereusablecellwithidentifier:@"cell" forindexpath:indexpath];     cell.cellcheckboximageview.image = [uiimage imagenamed:[nsstring stringwithformat:@"uncheckbox.png"]];      [self.selectedindexpaths removeobject:indexpath];      nslog(@"%ld", (long)indexpath.row); } 

why not omit

- (void)tableview:(uitableview *)tableview diddeselectrowatindexpath:(nsindexpath *)indexpath 

and try like

-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     if(![self.selectedindexpaths containsobject:indexpath])     {         [self.selectedindexpaths addobject:indexpath];     }     else     {         [self.selectedindexpaths removeobject:indexpath];     }     [tableview reloaddata];     nslog(@"%ld", (long)indexpath.row); } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -