我已经阅读了相关的答案,但没有任何工作。当第一次加载表时,一切正常,但滚动表后,所有内容都发生了变化。如果有人可以帮忙吗?这是我的代码。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[arrReportList objectAtIndex:section]count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
SummaryReportTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"summaryCell"];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"SummaryReportTableViewCell" owner:self options:nil] objectAtIndex:0];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[cell setCellLayoutWithArray:[[arrReportList objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]];
...
...
}
SummaryReportTableViewCell.m
-(void)setCellLayoutWithArray :(NSMutableArray *)array {
[btnViewPieChart setImage:[CommonMethod createIconWithIconName:@"fa-pie-chart" ForegroundColor:kColorEnableIcon BGColor:[UIColor clearColor] size:CGSizeMake(25, 25)] forState:UIControlStateNormal];
btnDomain.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
btnDomain.titleLabel.textAlignment = NSTextAlignmentLeft;
btnDomain.contentEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 0);
[btnDomain setTitle:[array valueForKey:@"DomainName"] forState:UIControlStateNormal];
[btnGoal setTitle:[array valueForKey:@"Goals"] forState:UIControlStateNormal];
[self UIButton:btnGoal withValue:btnGoal.titleLabel.text];
}
-(void)UIButton :(UIButton *)btn withValue:(NSString *)value {
if ([btn.titleLabel.text integerValue] > 0) {
[btn setBackgroundColor:kColorTabMenuBG];
btn.titleLabel.font = kFontBold(16);
btn.titleLabel.textColor = kColorTabDeActiveMenu;
btn.userInteractionEnabled = true;
} else {
[btn setBackgroundColor:[UIColor whiteColor]];
btn.titleLabel.font = kFontNormal(16);
btn.titleLabel.textColor = [UIColor blackColor];
btn.userInteractionEnabled = false;
}
}
第一次出镜
向下滚动表格后再次显示相同的数据
答案 0 :(得分:1)
我可以看到问题在细胞中是有色的。
原因:每当您将一个单元格出列后,它就会进入tableview的出列池并询问之前出列的单元格, 因此,当您向上滚动以前出列的单元格的完整数据时,新单元格会发生变化(数据源)您为新单元格所做的更改(如果您不更改任何属性,字段或数据源将保持与前一个单元格相同)。
解决方案:您为新单元格重新设置的数据因此值正常。创建一个单元模型或数据源,您也可以在其中添加单元格的背景颜色,以便它为每个单元格重置或根据您正在进行的业务逻辑显式更改颜色。