ios - Custom cell is Duplicating the properties of the other cell in the same Tableview -


i using custom cell uitableview in having few uilabels. in 1 label setting it's color red.that working fine me. reloading tableview egorefresh table delegate methods color of label of other cells start changing red color. don't know why problem coming , causing lot of disgust me.

this code tableview datasource method cellforrowatindexpath:

- (void)tableview:(uitableview *)tableview willdisplaycell:(uitableviewcell *)cell    forrowatindexpath:(nsindexpath *)indexpath{      // set frame backgroundview of cell.     nsdictionary * insurancedic = [arr_insurance objectatindex:indexpath.row];     insurancedic = [[appdelegate sharedinstance] removenullsfromdictonary:insurancedic];     insurancecell * mycell = (insurancecell *)cell;     if([[insurancedic valueforkey:@"active"] isequaltostring:@"n"]){         //tttregexattributedlabel * label = [[tttregexattributedlabel alloc] init];         mycell.lbl_insurancename.text =  [nsstring stringwithformat:@"%@ (%@)",        [insurancedic valueforkey:@"insurance_name"],@"inactive"];         mycell.lbl_insurancename.textcolor = [uicolor redcolor];         //[label settext:cell.lbl_insurancename.text withregex:@"(inactive)" withfont:      [uifont boldsystemfontofsize:12] withcolor:[uicolor redcolor]];     }     else{         mycell.lbl_insurancename.text = [insurancedic valueforkey:@"insurance_name"];     } } 

and on reloading table view these methods problem occuring :

#pragma mark - #pragma mark uiscrollviewdelegate methods  - (void)scrollviewdidscroll:(uiscrollview *)scrollview{ // top pull refresh.     [_refreshheaderview egorefreshscrollviewdidscroll:scrollview];    //for bottom pull refresh.     [pulltobottomrefreshmanager_ tableviewscrolled]; }  - (void)scrollviewdidenddragging:(uiscrollview *)scrollview willdecelerate:    (bool)decelerate{     // top pull refresh.     [_refreshheaderview egorefreshscrollviewdidenddragging:scrollview];     //for bottom pull refresh.     [pulltobottomrefreshmanager_ tableviewreleased]; }   #pragma mark - #pragma mark egorefreshtableheaderdelegate methods  // belowline stop refresh indicator //[_refreshheaderview    egorefreshscrollviewdatasourcedidfinishedloading:self.tableview];  - (void)egorefreshtableheaderdidtriggerrefresh:(egorefreshtableheaderview*)view{     // when going refresh data need reset start varible 1     // , removeallthe previous objects array.     str_start = @"1";     [self getinsurancelist]; }  - (bool)egorefreshtableheaderdatasourceisloading:(egorefreshtableheaderview*)view{       return isreloading; // should return if data source model reloading }  - (nsdate*)egorefreshtableheaderdatasourcelastupdated:    (egorefreshtableheaderview*)view{        return [nsdate date]; // should return date data source last changed  }  #pragma mark - #pragma mark mnmbottompulltorefreshmanagerclient methods - (void)bottompulltorefreshtriggered:(mnmbottompulltorefreshmanager *)manager {     // here incrementing start records per page means start+=recordsperpare     or start+=20.    str_start = [nsstring stringwithformat:@"%d",[str_start intvalue]+    [str_recordsperpage intvalue]];    [self getinsurancelist]; } 

this code cellforrowatindexpath method:

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:       (nsindexpath     *)indexpath{     static nsstring *cellidentifier = @"cell";     insurancecell  * cell = [insurancecell dequeorcreateintable:tableview];      //    uitableviewcell *cell = [tableview       dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {       cell = [[[insurancecell alloc] initwithstyle:uitableviewcellstyledefault        reuseidentifier:cellidentifier] autorelease];      }     nsdictionary * insurancedic = [arr_insurance objectatindex:indexpath.row];     insurancedic = [[appdelegate sharedinstance] removenullsfromdictonary:insurancedic];     cell.lbl_insuranceno.text = [insurancedic valueforkey:@"insurance_no"];     cell.lbl_groupno.text = [insurancedic valueforkey:@"group_no"];     cell.lbl_priority.text = [self getprioritydescfromcode:[insurancedic         valueforkey:@"priority"]];     cell.lbl_startdate.text = [insurancedic valueforkey:@"start_date"];     cell.lbl_enddate.text = [insurancedic valueforkey:@"end_date"];     cell.lbl_copay.text = [insurancedic valueforkey:@"copay"];     // condition setting alternate (white/skyblue) background color cell.    //    if (fmod(indexpath.row, 2)==0) {    //        cell.backgroundview.backgroundcolor = [uicolor colorfromrgbintegers:237       green:243 blue:249 alpha:1];    //            //    }    //    else{    //        cell.backgroundview.backgroundcolor = [uicolor colorfromrgbintegers:250   green:250 blue:250 alpha:1];    //    }     cell.selectionstyle = uitableviewcelleditingstylenone;    return cell;  } 

it if add cellforrowatindexpath: implementation.

given information provide suppose reusing cells , not resetting color before. need override - (void)prepareforreuse in insurancecell , reset cell specific properties.

sample implementation:

- (void)prepareforreuse {     [super prepareforreuse];     // reset label text color default color (e.g. black)     self.lbl_insurancename.textcolor = [uicolor blackcolor]; } 

you need implement method within insurancecell.

you need understand, default implementation of cellforrowatindexpath: tableviewcells reused. means need reset every property explicitly, before reuse cell. convenient way this, overriding prepareforreuse method, shown above.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -