objective c - iOS Expanded/Selected Custom UITableViewCells state changes when scrolling UITableView -


i have list of custom cells in tableview , scroll appears fine , cells appear in same order. have functionality cells - select cell (and dynamically expands)the background color changes , few other custom cell properties. once , start scrolling, different cells haven't touched before show up, selected(expanded) , cell updates when select manually correct data. seem see duplicates , kinds of craziness.

i know there lots of posts on here far me, far nothing has worked. input on stop ridiculous behavior.

i have posted code give better idea of doing. know 'dequeuereusablecellwithidentifier' culprit don't know of alternative.

as side notes, tableview(its own xib) child view of large view (also xib). have registered nib tableview.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      mycustomcell *cell = [tableview dequeuereusablecellwithidentifier:myindentifier forindexpath:indexpath];      if(self.currentselectedindex){          if(self.previousselectedindex){                 //collapse cell                 //configure cell in method(change background color etc)          }         else{          //expand cell          //configure cell in method(change background color etc)          }      }  }  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {      self.currentselectedindex = indexpath;     [tableview beginupdates];     if(self.currentselectedindex){         if(self.previousselectedindex && (self.previousselectedindex != self.currentselectedindex)){         [tableview reloadrowsatindexpaths:@[self.currentselectedindex, self.previousselectedindex] withrowanimation:uitableviewrowanimationautomatic];         }         else{             [tableview reloadrowsatindexpaths:@[self.currentselectedindex] withrowanimation:uitableviewrowanimationautomatic];         }     }     [tableview endupdates];      if(self.previousselectedindex == self.currentselectedindex){         self.previousselectedindex = nil;     }     else{         self.previousselectedindex = self.currentselectedindex;     } } 

what can or how make sure nothing else in list 'seems' selected(expanded) or prevent appearing see duplicates scroll? keep track of current , last selected index(as shown in code) suppose use somehow?

dequeued cells reused

know cells re-used, appearance of uitableviewcell persistent entire life of cell.

this means if not explicitly reset presentation view of cell, , returning unchanged in cellforrowatindexpath, returning may selected (or deselected) cached cell.

a possible location reset table cell prepareforreuse.


design note:
how maintaining self.currentselectedindex , self.previousselectedindex? typically quite dangerous, since attempting replicate uitableview behavior. example, unlikely work multiple selection. setting active selection unlikely handle situations when os diddeselectrowatindexpath, result of keyboard dismissal example.


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 -