Iphone UIStableView的UIScrollView问题
我有一个UITableview和UICutsom单元。在UITableview中,我使用web服务填充数据。我更改单元格的背景色和字体颜色。当我上下滚动该Tableview单元格时,另一个单元格的背景颜色和标签颜色也会发生变化Iphone UIStableView的UIScrollView问题,iphone,Iphone,我有一个UITableview和UICutsom单元。在UITableview中,我使用web服务填充数据。我更改单元格的背景色和字体颜色。当我上下滚动该Tableview单元格时,另一个单元格的背景颜色和标签颜色也会发生变化 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTabl
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"FieldInventoryCell";
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
FieldInventoryCell *cell=(FieldInventoryCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"FieldInventoryCell" owner:self options:nil];
cell=[nib objectAtIndex:0];
}
NSArray *ar = [[arr objectAtIndex:indexPath.row]componentsSeparatedByString:@"|"];
cell.Status.text=[ar objectAtIndex:1];
cell.serialnumber.text=[ar objectAtIndex:0];
cell.date.text=[ar objectAtIndex:2];
if([cell.serialnumber.text isEqualToString:@"Grand Total"])
{
cell.contentView.backgroundColor=[UIColor blueColor];
cell.serialnumber.textColor=[UIColor whiteColor];
}
if ([cell.serialnumber.text isEqualToString:@"INV_FLD Status Total"])
{
//cell.contentView.backgroundColor=[UIColor blueColor];
cell.serialnumber.textColor=[UIColor orangeColor];
}
return cell;
}
据我从你的帖子中了解到的,你可能遇到的问题与细胞出列有关。您正在为contentView和序列号标签设置一些颜色,但如果不满足条件,则不会重置它们。由于该表重用单元格,因此已着色的项将显示在新元素中。要解决此问题,请将颜色重置为默认值,例如
// ...
if([cell.serialnumber.text isEqualToString:@"Grand Total"])
{
cell.contentView.backgroundColor=[UIColor blueColor];
cell.serialnumber.textColor=[UIColor whiteColor];
} else {
// reset color
cell.contentView.backgroundColor=[UIColor clearColor];
cell.serialnumber.textColor=[UIColor blackColor];
}
if ([cell.serialnumber.text isEqualToString:@"INV_FLD Status Total"])
{
//cell.contentView.backgroundColor=[UIColor blueColor];
cell.serialnumber.textColor=[UIColor orangeColor];
} else {
// reset color
cell.serialnumber.textColor=[UIColor blackColor];
}
您尚未描述(或强调)实际问题是什么。你面临什么问题?你试过怎么解决它?