ios - UITableViewCell content of previous row is still visible on Cell reload -
i have uitableview
has 2 different custom uitableviewcell
2 different unique identifiers.
i load first custom uitableviewcell
on load
, second custom uitableviewcell
on cell select
.
i know problem related way reusing cells. i've tried using
routinesearchselectedresultcell * cell = (routinesearchselectedresultcell*)[tableview dequeuereusablecellwithidentifier:nil];
, result new uitableviewcell
empty , properties not populated.
i've tried [[[cell contentview] subviews] makeobjectsperformselector: @selector(removefromsuperview)];
give me same results.
how go around problem??
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { if (idp && idp.row == indexpath.row ) { return [self tableviewroutineselectedresult:tableview cellforrowatindexpath:indexpath]; } nsstring *cellidentifier = @"routinesearchcell"; routinesearchcell * cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (!cell) { cell = [[routinesearchcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier]; } cell.routinename.text = _mydownloadedinfo[@"routines"][indexpath.row][@"routine"][@"routinename"]; cell.routineauthor.text = _mydownloadedinfo[@"routines"][indexpath.row][@"routine"][@"username"]; return cell; } - (routinesearchselectedresultcell *)tableviewroutineselectedresult:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nsdictionary* myroutine = _mydownloadedinfo[@"routines"][indexpath.row][@"routine"]; [self sortoutroutineimages:myroutine[@"routinetype"]]; nsstring *cellidentifier = @"routinesearchselectedresultcell"; routinesearchselectedresultcell * cell = (routinesearchselectedresultcell*)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (!cell) { cell = [[routinesearchselectedresultcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier]; } cell.label1.text =@"test"; cell.contentview.backgroundcolor = [uicolor colorwithpatternimage:[uiimage imagenamed:@"blackgradientsearch"]]; cell = [self iconroutineimagescontroller:cell]; cell.imginstruction.image = [uiimage imagenamed:@"instructionsearchwhite"]; cell.imgvideos.image = [uiimage imagenamed:@"videosearchwhite"]; cell.routinename.text = myroutine[@"routinename"]; [cell.download setbackgroundimage:[uiimage imagenamed:@"downloadsearchwhite"] forstate:uicontrolstatenormal]; return cell; } - (void) tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { if ( idp ) { nsindexpath* pidp = [[nsindexpath alloc] init]; pidp = idp; idp = indexpath; [tableview beginupdates]; [tableview reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationleft]; [tableview reloadrowsatindexpaths:@[pidp] withrowanimation:uitableviewrowanimationright]; [tableview endupdates]; } else { idp = [[nsindexpath alloc]init]; idp = indexpath; [tableview beginupdates]; [tableview reloadrowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationleft]; [tableview endupdates]; } }
try override
-(void)prepareforreuse
if uitableviewcell object reusable—that is, has reuse identifier—this method invoked before object returned uitableview method dequeuereusablecellwithidentifier:. performance reasons, should reset attributes of cell not related content, example, alpha, editing, , selection state. table view's delegate in tableview:cellforrowatindexpath: should reset content when reusing cell. if cell object not have associated reuse identifier, method not called. if override method, must sure invoke superclass implementation.
see document
Comments
Post a Comment