gpt4 book ai didi

ios - 标签在滚动时在重复

转载 作者:行者123 更新时间:2023-12-01 17:09:22 24 4
gpt4 key购买 nike

我有一个屏幕,其中有一个UIScrollView。 UITableView嵌入其中。我遭受的问题是单元重用。我将在此处附上一些屏幕截图以阐明问题。

滚动之前:屏幕加载时。



滚动时:

然后向上滚动回:

如您所见,由于单元的重复使用,现在显示LBM代替日期。由于这是一个内置的组表单元,因此我无法使用prepForReuse。

我在这里附加cellForRowAtIndexPath的代码。

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell * cell = (UITableViewCell *)[tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:CellIdentifier] autorelease];
// Here we are creating Custom Label to Display the TakenTime and TakenDate of Vitals
// in center.
if (indexPath.row==0) {
lbl_title = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, 320, 33)];
lbl_title.textAlignment = UITextAlignmentCenter;
lbl_title.font = [UIFont boldSystemFontOfSize:14];
lbl_title.textColor = [UIColor whiteColor];
lbl_title.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:lbl_title];
}

}

switch (indexPath.row) {
case 0:
lbl_title.text = [NSString stringWithFormat:@"%@ %@",[dic_vitalsDictonary
valueForKey:@"taken_date"],[dic_vitalsDictonary valueForKey:@"taken_time"]];
break;
case 1:
cell.textLabel.text = @"Height";
NSString * str_height = [[dic_vitalsDictonary valueForKey:@"height"] floatValue]
> 0 ? [dic_vitalsDictonary valueForKey:@"height"] : @"";
cell.detailTextLabel.text = [self setDecimalFormatForString:str_height];
break;
case 2:
cell.textLabel.text = @"Weight";
NSString * str_weight = [[dic_vitalsDictonary valueForKey:@"weight"] floatValue] >
0 ? [dic_vitalsDictonary valueForKey:@"weight"] : @"";
cell.detailTextLabel.text = [self setDecimalFormatForString:str_weight];
break;
case 3:
cell.textLabel.text = @"Temperature";
NSString * str_temprature = [[dic_vitalsDictonary valueForKey:@"temp"] floatValue]
> 0 ? [dic_vitalsDictonary valueForKey:@"temp"] : @"";
cell.detailTextLabel.text = [self setDecimalFormatForString:str_temprature];
break;
case 4:
cell.textLabel.text = @"Blood Pressure";
NSString * str_lowbp = [dic_vitalsDictonary valueForKey:@"lowbp"];
NSString * str_highbp = [dic_vitalsDictonary valueForKey:@"highbp"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@/%@",[self
setDecimalFormatForString:str_lowbp],[self setDecimalFormatForString:str_highbp]];
break;
case 5:
cell.textLabel.text = @"Blood Sugar";
NSString * str_bs1 = [dic_vitalsDictonary valueForKey:@"bs_1"];
NSString * str_bs2 = [dic_vitalsDictonary valueForKey:@"bs_2"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@/%@",[self
setDecimalFormatForString:str_bs1],[self setDecimalFormatForString:str_bs2]];
break;
case 6:
cell.textLabel.text = @"Pulse";
NSString * str_pulse = [[dic_vitalsDictonary valueForKey:@"pulse"] floatValue] > 0
? [dic_vitalsDictonary valueForKey:@"pulse"] : @"";
cell.detailTextLabel.text = [self setDecimalFormatForString:str_pulse];
break;
case 7:
cell.textLabel.text = @"Resp";
NSString * str_resp = [[dic_vitalsDictonary valueForKey:@"resp"] floatValue] > 0 ?
[dic_vitalsDictonary valueForKey:@"resp"] : @"";
cell.detailTextLabel.text = [self setDecimalFormatForString:str_resp];
break;
case 8:
cell.textLabel.text = @"Oxygen";
NSString * str_oxyzen = [[dic_vitalsDictonary valueForKey:@"oxygen"] floatValue] >
0 ? [dic_vitalsDictonary valueForKey:@"oxygen"] : @"";
cell.detailTextLabel.text = [self setDecimalFormatForString:str_oxyzen];
break;
case 9:
cell.textLabel.text = @"Fatmass";
NSString * str_fatmass = [[dic_vitalsDictonary valueForKey:@"fatmass"] floatValue]
> 0 ? [dic_vitalsDictonary valueForKey:@"fatmass"] : @"";
cell.detailTextLabel.text = [self setDecimalFormatForString:str_fatmass];
break;
case 10:
cell.textLabel.text = @"LBM";
NSString * str_lbm = [[dic_vitalsDictonary valueForKey:@"lbm"] floatValue] > 0 ?
[dic_vitalsDictonary valueForKey:@"lbm"] : @"";
cell.detailTextLabel.text = [self setDecimalFormatForString:str_lbm];
break;
case 11:
cell.textLabel.text = @"HC";
NSString * str_hc = [[dic_vitalsDictonary valueForKey:@"hc"] floatValue] > 0 ?
[dic_vitalsDictonary valueForKey:@"hc"] : @"";
cell.detailTextLabel.text = [self setDecimalFormatForString:str_hc];
break;
case 12:
cell.textLabel.text = @"Peakflow";
NSString * str_peakflow = [[dic_vitalsDictonary valueForKey:@"peakflow"]
floatValue] > 0 ? [dic_vitalsDictonary valueForKey:@"peakflow"] : @"";
cell.detailTextLabel.text =[self setDecimalFormatForString:str_peakflow];
break;
default:
break;
}

// Set the Background Image for TableviewCell.
// if 1st row then we are showing different image to Display Vitals Date.

if (indexPath.row==0) {

cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage
imageNamed:@"HeaderNavigation.png"]];
}
else{
// Set the Background Image for TableviewCell.
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage
imageNamed:@"cell_background.png"]];
}

cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;

}

请提出一些克服这种情况的方法。我已经尝试了很多,但似乎并没有达到我的预期效果。我想防止单元格被重复使用,以使其在滚动过程中不会重复。

最佳答案

尝试为每个单元提供唯一的标识符,

 NSString *CellIdentifier =[NSString stringWithFormat:"Cell %d",indexpath.row];

不知道这是否是正确的方法,但是应该可以解决您的问题。

关于ios - 标签在滚动时在重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16685760/

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