在UItableview中滚动时,数据重叠…为什么?

在UItableview中滚动时,数据重叠…为什么?,uitableview,nsmutablearray,xml-parsing,Uitableview,Nsmutablearray,Xml Parsing,我有UItableview,其中每个单元格包含5个单元格,这些单元格表示一些已解析的xml数据。当UItableview在视图控制器的开头执行时,它会在NSMutableArray的正确单元格中显示正确的数据,但现在我的问题是当从xml文件中的数据会分散在不同的单元格中,表示不同的数据 第一个单元格索引1,但在刷新表单元格1后,显示数据单元格5或任何其他单元格,表示单元格实际上没有重叠,但其数据以错误的方式表示..我没有找到解决方案,请任何人帮助我 这是我的tableview单元格代码 -

我有
UItableview
,其中每个单元格包含5个单元格,这些单元格表示一些已解析的xml数据。当
UItableview
在视图控制器的开头执行时,它会在
NSMutableArray
的正确单元格中显示正确的数据,但现在我的问题是当从xml文件中的数据会分散在不同的单元格中,表示不同的数据

第一个单元格索引1,但在刷新表单元格1后,显示数据单元格5或任何其他单元格,表示单元格实际上没有重叠,但其数据以错误的方式表示..我没有找到解决方案,请任何人帮助我

这是我的tableview单元格代码

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


static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15.0];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
    cell.accessoryView = imageView;
    cell.accessoryType = UITableViewCellSelectionStyleNone;
    tableView.separatorColor = [UIColor clearColor];
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;


    cellView = [[[UIView alloc] initWithFrame:CGRectMake(5,8,290, 120)] autorelease];
    cellView.backgroundColor = [UIColor clearColor];
    cellView.tag =10;
    [cell.contentView addSubview:cellView];

    imgView = [[UIImageView alloc] initWithFrame:CGRectMake(2, 40, 48, 48)];
    imgView.image = [UIImage imageNamed:@"productbox.png"];
    imgView.layer.borderColor = [UIColor blackColor].CGColor;
    imgView.layer.borderWidth = 2.0;
    imgView.tag = 5;
    [cellView addSubview:imgView];


    CGRect idLabelRect = CGRectMake(65, 0, 190, 18);
    idLabel = [[[UILabel alloc] initWithFrame:idLabelRect] autorelease];
    idLabel.textAlignment = UITextAlignmentLeft;
    idLabel.textColor = [UIColor blackColor];
    idLabel.font = [UIFont systemFontOfSize:12];
    idLabel.backgroundColor = [UIColor clearColor];
    idLabel.layer.borderColor = [UIColor grayColor].CGColor;
    idLabel.tag = 0;

    CGRect statusRect = CGRectMake(65, 22, 190, 22);
    statusLabel = [[[UILabel alloc] initWithFrame:statusRect] autorelease];
    statusLabel.textAlignment = UITextAlignmentLeft;
    statusLabel.textColor = [UIColor blackColor];
    statusLabel.font = [UIFont systemFontOfSize:12];
    statusLabel.backgroundColor = [UIColor clearColor];
    statusLabel.layer.borderColor = [UIColor grayColor].CGColor;
    statusLabel.tag = 1;

    CGRect orderDateRect = CGRectMake(65, 48, 190, 22);
    orderDate = [[[UILabel alloc] initWithFrame:orderDateRect] autorelease];
    orderDate.textAlignment = UITextAlignmentLeft;
    orderDate.textColor = [UIColor blackColor];
    orderDate.font = [UIFont systemFontOfSize:12];
    orderDate.backgroundColor = [UIColor clearColor];
    orderDate.layer.borderColor = [UIColor grayColor].CGColor;
    orderDate.tag = 2;

    CGRect byRect = CGRectMake(65, 75, 190, 22);
    byLabel = [[[UILabel alloc] initWithFrame:byRect] autorelease];
    byLabel.textAlignment = UITextAlignmentLeft;
    byLabel.textColor = [UIColor blackColor];
    byLabel.font = [UIFont systemFontOfSize:12];
    byLabel.backgroundColor = [UIColor clearColor];
    byLabel.layer.borderColor = [UIColor grayColor].CGColor;
    byLabel.tag = 3;

    CGRect totalRect = CGRectMake(65, 98, 190, 22);
    totalLabel = [[[UILabel alloc] initWithFrame:totalRect] autorelease];
    totalLabel.textAlignment = UITextAlignmentLeft;
    totalLabel.textColor = [UIColor blackColor];
    totalLabel.font = [UIFont systemFontOfSize:12];
    totalLabel.backgroundColor = [UIColor clearColor];
    totalLabel.layer.borderColor = [UIColor grayColor].CGColor;
    totalLabel.tag = 4;

    [cellView addSubview:idLabel];
    [cellView addSubview:statusLabel];
    [cellView addSubview:orderDate];
    [cellView addSubview:byLabel];
    [cellView addSubview:totalLabel];

}

cellView = (UIView *)[cell.contentView viewWithTag:10];
imgView = (UIImageView *)[cellView viewWithTag:5];
idLabel = (UILabel *)[cellView viewWithTag:0];
statusLabel = (UILabel *)[cellView viewWithTag:1];
orderDate = (UILabel *)[cellView viewWithTag:2];
byLabel = (UILabel *)[cellView viewWithTag:3];
totalLabel = (UILabel *)[cellView viewWithTag:4];

x = [records count];
//NSLog(@" total number of row: %d",x);
if(y<x){
    NSLog(@"%d",y);
    //[self performSelector:@selector(tabledata:) withObject:[NSNumber numberWithInt:y]  afterDelay:0.0];
    if(y == indexPath.section){
    idLabel.text = [NSString stringWithFormat:@"Order Id: %@",[[records objectAtIndex:y] objectAtIndex:0]];
    statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:y] objectAtIndex:1]];
    orderDate.text = [NSString stringWithFormat:@"Date: %@",[[records objectAtIndex:y] objectAtIndex:2]];
    byLabel.text = [NSString stringWithFormat:@"By: %@",[[records objectAtIndex:y] objectAtIndex:3]];
    totalLabel.text = [NSString stringWithFormat:@"Total: %@",[[records objectAtIndex:y] objectAtIndex:4]];
    y++;

    }
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
静态NSString*MyIdentifier=@“MyIdentifier”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithFrame:CGRectZero重用标识符:MyIdentifier]自动释放];
cell.textlab.font=[UIFont fontWithName:@“Helvetica”大小:15.0];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
UIImageView*imageView=[[UIImageView alloc]initWithImage:[UIImageName:@“arrow.png”];
cell.accessoryView=图像视图;
cell.accessoryType=UITableViewCellSelectionStyleNone;
tableView.separatorColor=[UIColor clearColor];
tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
cellView=[[UIView alloc]initWithFrame:CGRectMake(5,8290120)]自动释放];
cellView.backgroundColor=[UIColor clearColor];
cellView.tag=10;
[cell.contentView addSubview:cellView];
imgView=[[UIImageView alloc]initWithFrame:CGRectMake(2,40,48,48)];
imgView.image=[UIImage ImageName:@“productbox.png”];
imgView.layer.borderColor=[UIColor blackColor].CGColor;
imgView.layer.borderWidth=2.0;
imgView.tag=5;
[cellView添加子视图:imgView];
CGRect idLabelRect=CGRectMake(65,0,190,18);
idLabel=[[UILabel alloc]initWithFrame:idLabelRect]autorelease];
idLabel.textAlignment=UITextAlignmentLeft;
idLabel.textColor=[UIColor blackColor];
idLabel.font=[UIFont systemFontOfSize:12];
idLabel.backgroundColor=[UIColor clearColor];
idLabel.layer.borderColor=[UIColor grayColor].CGColor;
idLabel.tag=0;
CGRect statusRect=CGRectMake(65,22,190,22);
statusLabel=[[UILabel alloc]initWithFrame:statusRect]autorelease];
statusLabel.textAlignment=UITextAlignmentLeft;
statusLabel.textColor=[UIColor blackColor];
statusLabel.font=[UIFont systemFontOfSize:12];
statusLabel.backgroundColor=[UIColor clearColor];
statusLabel.layer.borderColor=[UIColor grayColor].CGColor;
statusLabel.tag=1;
CGRect orderDateRect=CGRectMake(65,48,190,22);
orderDate=[[UILabel alloc]initWithFrame:orderDateRect]autorelease];
orderDate.textAlignment=UITextAlignmentLeft;
orderDate.textColor=[UIColor blackColor];
orderDate.font=[UIFont systemFontOfSize:12];
orderDate.backgroundColor=[UIColor clearColor];
orderDate.layer.borderColor=[UIColor grayColor].CGColor;
orderDate.tag=2;
CGRect byRect=CGRectMake(65,75,190,22);
byLabel=[[UILabel alloc]initWithFrame:byRect]autorelease];
byLabel.textAlignment=UITextAlignmentLeft;
byLabel.textColor=[UIColor blackColor];
byLabel.font=[UIFont systemFontOfSize:12];
byLabel.backgroundColor=[UIColor clearColor];
byLabel.layer.borderColor=[UIColor grayColor].CGColor;
byLabel.tag=3;
CGRect totalRect=CGRectMake(65,98,190,22);
TotalAbel=[[UILabel alloc]initWithFrame:totalRect]autorelease];
totalAbel.textAlignment=UITextAlignmentLeft;
totalabel.textColor=[UIColor blackColor];
totalAbel.font=[UIFont systemFontOfSize:12];
TotalAbel.backgroundColor=[UIColor clearColor];
TotalAbel.layer.borderColor=[UIColor grayColor].CGColor;
totalabel.tag=4;
[cellView addSubview:idLabel];
[cellView addSubview:statusLabel];
[cellView addSubview:orderDate];
[cellView addSubview:byLabel];
[cellView addSubview:TotalAbel];
}
cellView=(UIView*)[cell.contentView视图带标记:10];
imgView=(UIImageView*)[cellView视图带标记:5];
idLabel=(UILabel*)[cellView视图带标记:0];
statusLabel=(UILabel*)[cellView视图带标记:1];
orderDate=(UILabel*)[cellView视图带标记:2];
byLabel=(UILabel*)[cellView视图带标记:3];
totalLabel=(UILabel*)[cellView视图带标记:4];
x=[记录计数];
//NSLog(@“总行数:%d”,x);
if(y0){
NSLog(@“scrollView.contentOffset.y 1=%d”,scrollView.contentOffset.y);
tableview.contentInset=UIEdgeInsetsZero;
}
else if(scrollView.contentOffset.y>=-刷新\u标题\u高度){
NSLog(@“scrollView.contentOffset.y2=%d”,scrollView.contentOffset.y);
tableview.contentInset=UIEdgeInsetsMake(-scrollView.contentOffset.y,0,0,0);
}
}else if(isDraging&&scrollView.contentOffset.y<0){
//更新箭头方向和标签
[UIView beginAnimations:nil上下文:NULL];
if(scrollView.contentOffset.y<-刷新页眉高度){
//用户正在标题上方滚动
NSLog(@“scrollView.contentOffset.y 3=%d”,scrollView.contentOffset.y);
refreshLabel.text=self.textRelease;
[refreshArrow layer].transform=CATTransformrM3dMakeRotation(M_PI,0,0,1);
}否则{//用户正在标题中的某个位置滚动
refreshLabel.text=self.textPull;
[refreshArrow layer].transform=CATTransformrM3dMakeRotation(M_PI*2,0,0,1);
}
[UIView委员会];
}
}
-(无效)ScrollViewDiEndDraging:(UIScrollView*)scrollView将减速:(BO
  - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if (isLoading) return;
isDragging = YES;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (isLoading) {
    // Update the content inset, good for section headers
    if (scrollView.contentOffset.y > 0){
        NSLog(@"scrollView.contentOffset.y 1= %d",scrollView.contentOffset.y );
        tableview.contentInset = UIEdgeInsetsZero;
    }
    else if (scrollView.contentOffset.y >= -REFRESH_HEADER_HEIGHT){
        NSLog(@"scrollView.contentOffset.y 2= %d",scrollView.contentOffset.y  );
        tableview.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
    }
} else if (isDragging && scrollView.contentOffset.y < 0) {
    // Update the arrow direction and label
    [UIView beginAnimations:nil context:NULL];
    if (scrollView.contentOffset.y < -REFRESH_HEADER_HEIGHT) {
        // User is scrolling above the header
        NSLog(@"scrollView.contentOffset.y 3= %d",scrollView.contentOffset.y      );
        refreshLabel.text = self.textRelease;
        [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
    } else { // User is scrolling somewhere within the header
        refreshLabel.text = self.textPull;
        [refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
    }
    [UIView commitAnimations];
   }
}

 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
   if (isLoading) return;
   isDragging = NO;
   if (scrollView.contentOffset.y <= -REFRESH_HEADER_HEIGHT) {
    // Released above the header
    [self startLoading];
   }
 }


return cell;
}