gpt4 book ai didi

ios - 当单元格离开屏幕时,Tableview 单元格内容会更改

转载 作者:行者123 更新时间:2023-11-29 00:54:37 26 4
gpt4 key购买 nike

我有两种 tableview 单元格,比如付费和未付费。我在左边有复选框,未付费单元格。第一次加载 tableview 时,所有单元格的格式都是正确的。但是当我向上滚动时,当单元格离开屏幕并返回屏幕时,它们的内容发生了变化。显示图像。 enter image description here

上下滚动后我明白了。

enter image description here

真的很郁闷。我搜索过 SO ,但无济于事。

我的代码如下:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


data1 = [[responseDict valueForKey:@"cases"]objectAtIndex:indexPath.section];
data1 = [data1 valueForKey:@"procedures"];
data1 = [data1 objectAtIndex:indexPath.row];
//[[[valueForKey:@"paid"]objectAtIndex:indexPath.row]valueForKey:@"procedures"];
static NSString *CellIdentifier = @"Cell";

//if ([payemtStr isEqual:@"0"]) {
//UnpiadCell



UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}


UIButton * checkBtn= (UIButton *)[cell viewWithTag:101];
UILabel *payToLbl = (UILabel *)[cell viewWithTag:100];
UIButton * expandBtn= (UIButton *)[cell viewWithTag:106];

if ([[data1 valueForKey:@"paid"]boolValue] ==1) {
payToLbl.text = @"";
[checkBtn setHidden:YES];
[expandBtn setHidden:YES];
cell.contentView.backgroundColor = [UIColor whiteColor];
}
else {
payToLbl.text = @"Pay to";
[checkBtn addTarget:self action:@selector(checkBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[expandBtn addTarget:self action:@selector(collapseExpandButtonTap:) forControlEvents:UIControlEventTouchUpInside];
if([[[selectedCellsArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row ] isEqualToString:@"Uncheck"])
[checkBtn setImage:[UIImage imageNamed:@"unchecked.png"] forState:UIControlStateNormal];
else
[checkBtn setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
// [[expandCellsArray objectAtIndex:indexPath.row] isEqualToString:@"Expand"]
if([[[expandCellsArray objectAtIndex:indexPath.section]objectAtIndex:indexPath.row ] isEqualToString:@"Expand"])
[expandBtn setImage:[UIImage imageNamed:@"collapse.png"] forState:UIControlStateNormal];
else
[expandBtn setImage:[UIImage imageNamed:@"expand.png"] forState:UIControlStateNormal];

// if ([selectedCellsArray containsObject:@"Check"]) {
// self.payBtn.hidden = NO;
// }
// else {
// self.payBtn.hidden = YES;
// }

}


UILabel *mainTitleLbk = (UILabel *)[cell viewWithTag:102];
mainTitleLbk.textColor= [UIColor blackColor];
mainTitleLbk.text = [data1 valueForKey:@"provider"];
((UILabel *)[cell viewWithTag:103]).text = [data1 valueForKey:@"description"];
((UILabel *)[cell viewWithTag:104]).text = [NSString stringWithFormat:@"%@ %@ ",
[data1 valueForKey:@"line_1"],
[data1 valueForKey:@"line_2"]
];
((UILabel *)[cell viewWithTag:109]).text = [NSString stringWithFormat:@"%@, %@", [data1 valueForKey:@"city"],[data1 valueForKey:@"state"]];

// [data1 valueForKey:@"zip"]
((UILabel *)[cell viewWithTag:105]).text = [NSString stringWithFormat:@"%@ ,%@" ,[data1 valueForKey:@"zip"],[data1 valueForKey:@"phone"]];
// handeling check uncheck buttons
return cell;


}

最佳答案

每次出现新行时,UITableViewCell 都会被重用。所以上下滚动之后,第一行不是新建的UITableviewCell。添加 2 行代码可能会解决问题:

{
payToLbl.text = @"Pay to";
[checkBtn setHidden:NO];
[expandBtn setHidden:NO];
.......

请同时清除这些按钮操作。

关于ios - 当单元格离开屏幕时,Tableview 单元格内容会更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37743110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com