1 .在未加“2”(如代码段中所指)中所指的红色代码之前,在用onSheetDidDone给cell中的
_carProLabel赋值时,会出现重叠现象。
2 . 当加上“2”中的代码时,就不会出现重叠现象了。
原因在于,在每次赋值时,都会将之前的cell中的label给移除掉,然后冲新生成一个label,然后给它赋值就不会出现重叠了
else if (indexPath.section == 1)
{
if (indexPath.row == 0)
{
cell.textLabel.text = @"车牌号";
NSString *_pro = nil;
NSString *_carNum = nil;
_rightDrivesingImageView = [[UIImageView alloc]init];
_rightDrivesingImageView.tag = 1002;
_rightDrivesingImageView.image = [UIImage imageNamed:@"icon-driver-my-next"];
UIImageView *_lineImageView = [[UIImageView alloc]init];
_lineImageView.tag = 1003;
_lineImageView.image = [UIImage imageNamed:@"icon-driver-my-line"];
_carProLabel= [self generateLabel];
_carProLabel.tag = 1004;
[_carProLabel setTextColor:[CHUtil colorWithHexString:@"ff6230"]];
if ([_driverAuthInfo.carPlateNumber length] > 0)
{
_pro = [_driverAuthInfo.carPlateNumber substringToIndex:1];
_carNum = [_driverAuthInfo.carPlateNumber substringFromIndex:1];
[_rightCarNumberTextFeild setTextColor: [UIColor blackColor]];
strs = _carNum;
_rightCarNumberTextFeild.text = strs;
}
else
{
strs = @"请输入车牌号";
_rightCarNumberTextFeild.placeholder = strs;
}
CGSize textSize = [CHUtil getTextCGSize:strs Font:_rightCarNumberTextFeild.font];
_rightCarNumberTextFeild.frame = CGRectMake(kDEVICEWIDTH - textSize.width - 15-35, 15, textSize.width+25, textSize.height);
[cell addSubview:_rightCarNumberTextFeild];
if ([_driverAuthInfo.carPlateNumber length] > 0)
{
<span style="color:#ff6666;">if (_carProLabel != nil)------1
{
[(UILabel*)[cell viewWithTag:1004] removeFromSuperview];
}
_carProLabel= [self generateLabel];
_carProLabel.tag = 1004;
[_carProLabel setTextColor:[UIColor redColor]];</span>
if (_rightDrivesingImageView != nil)
{
[(UIImageView*)[cell viewWithTag:1002] removeFromSuperview];
}
_rightDrivesingImageView = [[UIImageView alloc]init];
_rightDrivesingImageView.tag = 1002;
_rightDrivesingImageView.image = [UIImage imageNamed:@"icon-driver-my-next"];
if (_lineImageView != nil)
{
[(UIImageView*)[cell viewWithTag:1003] removeFromSuperview];
}
UIImageView *_lineImageView = [[UIImageView alloc]init];
_lineImageView.tag = 1003;
_lineImageView.image = [UIImage imageNamed:@"icon-driver-my-line"];
[_lineImageView setFrame:CGRectMake(kDEVICEWIDTH - 55 - 50-20, 11, 0.5, cellIimagehight)];
[_carProLabel setText: _pro];
[_carProLabel setFrame: CGRectMake(kDEVICEWIDTH - textSize.width - 30 - cellImageWidth -50-50, 14, textSize.width, textSize.height)];
[_rightDrivesingImageView setFrame:CGRectMake(kDEVICEWIDTH - 55 - 50-40, 11, cellImageWidth, cellIimagehight)];
}
else
{
<span style="color:#ff0000;">if (_carProLabel != nil)-----2
{
[(UILabel*)[cell viewWithTag:1004] removeFromSuperview];
}
_carProLabel= [self generateLabel];
_carProLabel.tag = 1004;
[_carProLabel setTextColor:[UIColor redColor]];
[_carProLabel setText: @"京"];
[_carProLabel setFrame: CGRectMake(kDEVICEWIDTH - textSize.width - 30 - cellImageWidth -50-50, 14, textSize.width, textSize.height)];</span>
[_rightDrivesingImageView setFrame:CGRectMake(kDEVICEWIDTH - 55 - 50-40, 11, cellImageWidth, cellIimagehight)];
[_lineImageView setFrame:CGRectMake(kDEVICEWIDTH - 55 - 50-20, 11, 0.5, cellIimagehight)];
}
[cell addSubview:_lineImageView];
[cell addSubview:_carProLabel];
[cell addSubview:_rightDrivesingImageView];
_pickerView = [[CHPickerWidgetView alloc]initWithColumn:1];
_pickerView.tag = 0;
}
在其他地方给label赋值,如红色字体。
#pragma mark -
#pragma mark sheet delegate method
- (void)onSheetDidDone
{
if (_pickerView.tag == 0)
{
if([_pickerView.dataSourceOne count]>0)
{
<span style="color:#ff0000;">_carProLabel.text = [_pickerView.dataSourceOne objectAtIndex:_pickerView.currentrow];</span>
}
}