我已阅读相关答案,但没有任何效果。当第一次加载表格时,一切都很好,但是当我滚动表格后,一切都改变了。如果有人可以帮忙吗?这是我的代码。
- (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;
}
}
第一次上图
再次向下和向上滚动表格后的数据相同
最佳答案
我可以看到问题出在单元格中。
原因:每当您将一个单元格出队时,它都会进入 tableview 的出队池并请求先前出队的单元格, 因此,当您向上滚动前一个出队单元格的完整数据时,新单元格将出现,并且您为新单元格所做的任何更改(数据源)都会反射(reflect)出来,如果您不更改任何属性、字段或数据源,它们将与前一个单元格保持相同。
解决方案:您正在为新单元格重新设置数据,因此值正常。创建一个单元格模型或数据源,您还可以在其中添加单元格的背景颜色,以便它为每个单元格重置或根据您正在制作的任何业务逻辑显式更改颜色。
关于ios - 当我滚动 tableview 时,UITableViewCell 会更改数据和设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47747038/