uitableview - iOS get current and previous selected UITableViewCells from cellForRowAtIndexPath method -


so doing expanding cells selecting on them , using heightforrowatindexpath change height , if select on again or select different cell cells expand or go normal size.

however, upon cell expanding have data show in expanded section, change background color of cell , set other properties have defined in tableviewcell subclass. example when cell in normal height background light green. when expanded needs white. set tableviewcell subclass property (a bool) when time loop through cells again (cellforrowatindexpath) can update these properties needed. unfortunately, haven't been able find way current cell thats been selected in cellforrowatindexpath.

here relevant code below. keep in mind want keep track of current cell selected , previous cell (if different current one) can update both cells properties. 1 cell can expanded @ time. when current cell selected , expanded previous one(if applicable) contract normal height. configurecell method there assign properties based bool property.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      mycustomcell *cell = [tableview dequeuereusablecellwithidentifier:myidentifier forindexpath:indexpath];      [cell configurecell:self.item[indexpath.row] iscollapsed:cell.iscollapsed];      return cell; }   - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {      mycustomcell *currentcell;     mycustomcell *previouscell;      self.currentselectedindex = indexpath;     //assign previous , current if previous nil     if(!self.previousselectedindex){         self.previousselectedindex = self.currentselectedindex;         currentcell = [tableview cellforrowatindexpath:self.currentselectedindex];         currentcell.iscollapsed = no;     }     //we have tapped same cell before     else if(self.previousselectedindex == self.currentselectedindex){         previouscell = [tableview cellforrowatindexpath:self.previousselectedindex];         previouscell.iscollapsed = yes;         self.previousselectedindex = self.currentselectedindex = nil;     }     //if aren't equal, collapse previous selected cell     //and expand current selected cell     else{         previouscell = [tableview cellforrowatindexpath:self.previousselectedindex];         previouscell.iscollapsed = yes;          currentcell = [tableview cellforrowatindexpath:self.currentselectedindex];         currentcell.iscollapsed = no;         self.previousselectedindex = self.currentselectedindex;      }      [tableview beginupdates];   if(self.currentselectedindex){     [tableview reloadrowsatindexpaths:@[self.currentselectedindex, self.previousselectedindex] withrowanimation:uitableviewrowanimationautomatic]; }      [tableview endupdates]; } 

so, current , previous cell trashed once leave method since local struggling how to:

a. reload cells cause cellforrowatindexpath execute again(this works when trying use reloadrows - maybe i'm doing wrong)

b.once cellforrowatindex starts going through cells how capture currentcell , previouscell can update content described above. [dequeuereusablecellwithidentifier:myidentifier] gets new cell not want obviously.

the cells expand , contract fine thats not issue.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -