ios - Custom cell in UITableView make images overlap on scroll -
i have created custom table view cell have 2 images on (initially set hidden). when render each cell check status , set images visible/hidden property. when open table looks fine when scroll bottom , top first 2-3 cells have both image displayed.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ static nsstring *cellidentifier = @"mycustomcell";{ ordercustomcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if(cell == nil){ [tableview registernib:[uinib nibwithnibname:@"mycustomcell" bundle:nil] forcellreuseidentifier:cellidentifier]; cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; } ... cell.title.text = @"some value"; ... if(...){ cell.image1.hidden = yes; cell.image2.hidden = no; } else{ cell.image1.hidden = no; cell.image2.hidden = yes; } ...
why happen? problem maybe cellidentifier
. update first try:
ordercustomcell *cell; if(cell == nil){ [tableview registernib:[uinib nibwithnibname:@"mycustomcell" bundle:nil] forcellreuseidentifier:cellidentifier]; cell = [tableview dequeuereusablecellwithidentifier:nil]; }
second try:
ordercustomcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if(cell == nil){ [tableview registernib:[uinib nibwithnibname:@"mycustomcell" bundle:nil] forcellreuseidentifier:nil]; cell = [tableview dequeuereusablecellwithidentifier:nil]; }
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ static nsstring *cellidentifier = @"mycustomcell"; ordercustomcell *cell = [tableview dequeuereusablecellwithidentifier:nil]; if(cell == nil){ [tableview registernib:[uinib nibwithnibname:@"mycustomcell" bundle:nil] forcellreuseidentifier:cellidentifier]; cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; } ... cell.title.text = @"some value"; ... if(...){ cell.image1.hidden = yes; cell.image2.hidden = no; } else{ cell.image1.hidden = no; cell.image2.hidden = yes; } ...
ios objective-c uitableview
No comments:
Post a Comment