ios - UITableViewCell reusability issue. Modifying one cell is affecting others -
whenever cell section 3 selected. i'm updating datasource array, , cell's background color changing correctly.
however, whenever scroll start seeing random cells modified background color, knowing don't mention in cellforrowatindexpath
method , each section in tableview
populated separate datasource array/dictionary
!
(i'm using storyboard handle ui setup)
here's code (focus on section 3)
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { ectextfieldtableviewcell *cell = [tableview dequeuereusablecellwithidentifier:ksettingstextfieldcellreuseidentifier forindexpath:indexpath]; if (indexpath.section == 0) { cell.celltextfield.text = [self.personalinfodatasource valueforkey:kuservalueskey][indexpath.row]; } else if (indexpath.section == 1) { cell.celltextfield.text = [self.contactinfodatasource valueforkey:kuservalueskey][indexpath.row]; } else if (indexpath.section == 2) { cell.celltextfield.text = [self.professionaldetailsdatasource valueforkey:kuservalueskey][indexpath.row]; } else if (indexpath.section == 3) { //---- problems here usermeta *metaobj = self.interestdatasource[indexpath.row]; cell.celltextfield.userinteractionenabled = no; cell.celltextfield.text = metaobj; if (self.user.interest.count > 0 && [self.user.interest contains:metaobj.name] ) { cell.backgroundcolor = [uicolor redcolor]; } } return cell; }
and here's i'm doing datasource modifications
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { if (indexpath.section == 0 && indexpath.row == 2) { // stuff } else if (indexpath.section == 3) { //---- problems here ectextfieldtableviewcell *cell = [self.tableview cellforrowatindexpath:indexpath]; cell.backgroundcolor = [uicolor redcolor]; usermeta *metaobj = self.interestdatasource[indexpath.row]; [self.user.interest addobject:metaobj]; } }
as wrote, cells reused. cell displayed in section 3 reused in section 0.
therefore have make sure all parameters set defined state.
that means if set userinteractionenabled
no
, background color depending on condition red in section 3 have set userinteractionenabled
yes
, color default color in other sections. further have set color default color in section 3 if condition false.
Comments
Post a Comment