objective c - UITableViewCell changes Content after scrolling -
my problem: of custom uitableviewcells contain uilabel , uiview additional information. in code remove these uilabel , uiview when there no information object. every time user scrolls through uitableview these labels hidden although there additional information these cell , shown in cell.
here code:
-(uitableviewcell*)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{ nbsnacktableviewcell *cell = [self.tableview dequeuereusablecellwithidentifier:@"cell"]; nsdictionary *softdrinkdict = [_allsoftdrinksarray objectatindex:indexpath.row]; cell.snacknamelabel.text = [softdrinkdict valueforkey:@"name"]; cell.snackpricelabel.text = [nsstring stringwithformat:@"%@ - %@", [softdrinkdict valueforkey:@"size"], [softdrinkdict valueforkey:@"preis"]]; if ([softdrinkdict valueforkey:@"info"]) { cell.accessorytype = uitableviewcellaccessorydetailbutton; cell.tintcolor = [nbcolor primarytextcolor]; cell.snackinfolabel.text = [softdrinkdict valueforkey:@"info"]; } else { cell.accessorytype = uitableviewcellaccessorynone; [cell.snackinfolabel removefromsuperview]; [cell.snackinfoview removefromsuperview]; } if ([softdrinkdict valueforkey:@"zusatzstoffe"]) { cell.snackzusatzstofflabel.text = [softdrinkdict valueforkey:@"zusatzstoffe"]; } else { [cell.snackzusatzstofflabel removefromsuperview]; } [cell layoutcontentwithrect:cell.bounds]; return cell;}
i see problem:
you're removing label superview not re-adding subview of cell.
instead of calling removefromsuperview on labels, either set text @"" or make sure add label cell's contentview when there data displayed.
example:
if ([softdrinkdict valueforkey:@"zusatzstoffe"]) { if (![cell.snackzusatzstofflabel isdescendantofview:cell.contentview]) { [cell.contentview addsubview:cell.snackzusatzstofflabel]; } cell.snackzusatzstofflabel.text = [softdrinkdict valueforkey:@"zusatzstoffe"]; } else { [cell.snackzusatzstofflabel removefromsuperview]; }
Comments
Post a Comment