谁能告诉我为什么表格视图数据在滚动之前不显示?

发布于 2024-12-23 02:01:12 字数 4342 浏览 1 评论 0原文

在我的表视图中,我设置了要显示的 xml 数据,但在滚动之前它不会显示所有值。当我获取 xml 数据时,我已经重新加载了 tableview。我还使用了 [cell.contenView viewWithTag:tagnumber]; 但现在它仍然不起作用......请帮助我......

数据正在到来并使用 NSLog 我可以获取该值,但直到滚动后才会显示。有人认为我必须提到我可以看到我的单元格视图和图像视图,但不显示标签数据。

 - (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 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:MyIdentifier] autorelease];
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15.0];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

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

          // THIS IS A VIEW ABOVE MY CELL NAME: cellView    

    cellView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,290, 120)] autorelease];
    cellView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"order_description_bg.png"]];
    cellView.tag =10;

         // THIS IS A IMAGEVIEW ABOVE MY cellView NAME: imgView

    imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 39, 36)];
    imgView.image = [UIImage imageNamed:@"order_image.png"];
    imgView.layer.borderColor = [UIColor blackColor].CGColor;
    imgView.layer.borderWidth = 0.0f;
    imgView.tag = 5;

           // THIS IS A LABEL ABOVE MY cellView NAME: statusLabel

            CGRect statusRect = CGRectMake(65, 0, 190, 18);
    statusLabel = [[[UILabel alloc] initWithFrame:statusRect] autorelease];
    statusLabel.textAlignment = UITextAlignmentLeft;
    statusLabel.textColor = [UIColor blackColor];
    statusLabel.font = [UIFont systemFontOfSize:12];
    statusLabel.backgroundColor = [UIColor greenColor];
    statusLabel.tag = 1;

    [cell.contentView addSubview:cellView];
    [cellView addSubview:statusLabel];
    [cellView addSubview:imgView];

}


  //  [cell.contentView superview];
cellView = (UIView *)[cell.contentView viewWithTag:10];
imgView = (UIImageView *)[cellView viewWithTag:5];
statusLabel = (UILabel *)[cellView viewWithTag:1];

if(searching == YES && x<=inumOfRowAfterSearch){
        NSLog(@"[[searchData objectAtIndex:m] intValue] is : %d",[[searchData objectAtIndex:inumOfRowAfterSearch] intValue]);
            y = [[searchData objectAtIndex:inumOfRowAfterSearch] intValue];

    cellView = (UIView *)[cell.contentView viewWithTag:10];
    imgView = (UIImageView *)[cellView viewWithTag:5];
    statusLabel = (UILabel *)[cellView viewWithTag:1];

    if(pendingOrder == NO && todaysOrder == NO && x<=inumOfRowAfterSearch){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:y] objectAtIndex:1]];
     }
    else if(pendingOrder == YES && todaysOrder == NO && x<=inumOfRowAfterSearch){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:y] objectAtIndex:1]];
    }
}
else{

    cellView = (UIView *)[cell.contentView viewWithTag:10];
    imgView = (UIImageView *)[cellView viewWithTag:5];
    statusLabel = (UILabel *)[cellView viewWithTag:1];

    if(pendingOrder == NO && todaysOrder == NO){
      statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:indexPath.section] objectAtIndex:1]];
        NSLog(@"status lable value: %@",statusLabel.text);
        }
    else if(pendingOrder == YES && todaysOrder == NO){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[pendingRecords objectAtIndex:indexPath.section] objectAtIndex:1]];
        }
}
return cell;
}

在滚动表格之前。

在此处输入图像描述

滚动桌面视图后

“在此输入图像描述”

In my tableview i have set xml data to display but until scroll it does not display all value. I have reloaded the tableview when i am getting my xml data. I also used [cell.contenView viewWithTag:tagnumber]; But still now its not Working...please help me anybody....

Data are coming and using NSLog i can get the value but not display until scroll.
One think i have to mention that i can see the my cellview and imageview but not showing lable data.

 - (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 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:MyIdentifier] autorelease];
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:15.0];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

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

          // THIS IS A VIEW ABOVE MY CELL NAME: cellView    

    cellView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,290, 120)] autorelease];
    cellView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"order_description_bg.png"]];
    cellView.tag =10;

         // THIS IS A IMAGEVIEW ABOVE MY cellView NAME: imgView

    imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 39, 36)];
    imgView.image = [UIImage imageNamed:@"order_image.png"];
    imgView.layer.borderColor = [UIColor blackColor].CGColor;
    imgView.layer.borderWidth = 0.0f;
    imgView.tag = 5;

           // THIS IS A LABEL ABOVE MY cellView NAME: statusLabel

            CGRect statusRect = CGRectMake(65, 0, 190, 18);
    statusLabel = [[[UILabel alloc] initWithFrame:statusRect] autorelease];
    statusLabel.textAlignment = UITextAlignmentLeft;
    statusLabel.textColor = [UIColor blackColor];
    statusLabel.font = [UIFont systemFontOfSize:12];
    statusLabel.backgroundColor = [UIColor greenColor];
    statusLabel.tag = 1;

    [cell.contentView addSubview:cellView];
    [cellView addSubview:statusLabel];
    [cellView addSubview:imgView];

}


  //  [cell.contentView superview];
cellView = (UIView *)[cell.contentView viewWithTag:10];
imgView = (UIImageView *)[cellView viewWithTag:5];
statusLabel = (UILabel *)[cellView viewWithTag:1];

if(searching == YES && x<=inumOfRowAfterSearch){
        NSLog(@"[[searchData objectAtIndex:m] intValue] is : %d",[[searchData objectAtIndex:inumOfRowAfterSearch] intValue]);
            y = [[searchData objectAtIndex:inumOfRowAfterSearch] intValue];

    cellView = (UIView *)[cell.contentView viewWithTag:10];
    imgView = (UIImageView *)[cellView viewWithTag:5];
    statusLabel = (UILabel *)[cellView viewWithTag:1];

    if(pendingOrder == NO && todaysOrder == NO && x<=inumOfRowAfterSearch){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:y] objectAtIndex:1]];
     }
    else if(pendingOrder == YES && todaysOrder == NO && x<=inumOfRowAfterSearch){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:y] objectAtIndex:1]];
    }
}
else{

    cellView = (UIView *)[cell.contentView viewWithTag:10];
    imgView = (UIImageView *)[cellView viewWithTag:5];
    statusLabel = (UILabel *)[cellView viewWithTag:1];

    if(pendingOrder == NO && todaysOrder == NO){
      statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:indexPath.section] objectAtIndex:1]];
        NSLog(@"status lable value: %@",statusLabel.text);
        }
    else if(pendingOrder == YES && todaysOrder == NO){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[pendingRecords objectAtIndex:indexPath.section] objectAtIndex:1]];
        }
}
return cell;
}

Before scroll the table.

enter image description here

After Scroll the tableview

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

计㈡愣 2024-12-30 02:01:12

以下代码并不是每个条件都必需的,因为您已在条件之外编写了代码。看起来重复。

cellView = (UIView *)[cell.contentView viewWithTag:10];
imgView = (UIImageView *)[cellView viewWithTag:5];
statusLabel = (UILabel *)[cellView viewWithTag:1];

说到你的问题,它似乎最初会跳过 ifelse if 条件。还要注释 NSLog 并在条件的 else 部分中写入 NSLog

编辑:

//  [cell.contentView superview];
cellView = (UIView *)[cell.contentView viewWithTag:10];
imgView = (UIImageView *)[cellView viewWithTag:5];
statusLabel = (UILabel *)[cellView viewWithTag:1];

if(searching == YES && x<=inumOfRowAfterSearch){
    NSLog(@"[[searchData objectAtIndex:m] intValue] is : %d",[[searchData objectAtIndex:inumOfRowAfterSearch] intValue]);
    y = [[searchData objectAtIndex:inumOfRowAfterSearch] intValue];

    if(pendingOrder == NO && todaysOrder == NO ){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:y] objectAtIndex:1]];
    }
    else if(pendingOrder == YES && todaysOrder == NO ){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:y] objectAtIndex:1]];
    }
    else
    {
        statusLabel.text = [NSString stringWithFormat:@"Status: None"];
    }
}
else{
    if(pendingOrder == NO && todaysOrder == NO){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:indexPath.section] objectAtIndex:1]];
        NSLog(@"status lable value: %@",statusLabel.text);
    }
    else if(pendingOrder == YES && todaysOrder == NO){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[pendingRecords objectAtIndex:indexPath.section] objectAtIndex:1]];
    }
    else
    {
        statusLabel.text = [NSString stringWithFormat:@"Status: None"];
    }
}
return cell;

Following codes are not necessary in each condition , since you have written the code outside of the condition. It seems duplicate.

cellView = (UIView *)[cell.contentView viewWithTag:10];
imgView = (UIImageView *)[cellView viewWithTag:5];
statusLabel = (UILabel *)[cellView viewWithTag:1];

And coming to your question, it seems initially it skips both if and else if conditions. Comment also the NSLogs and write NSLog in else part of the conditions.

Edit:

//  [cell.contentView superview];
cellView = (UIView *)[cell.contentView viewWithTag:10];
imgView = (UIImageView *)[cellView viewWithTag:5];
statusLabel = (UILabel *)[cellView viewWithTag:1];

if(searching == YES && x<=inumOfRowAfterSearch){
    NSLog(@"[[searchData objectAtIndex:m] intValue] is : %d",[[searchData objectAtIndex:inumOfRowAfterSearch] intValue]);
    y = [[searchData objectAtIndex:inumOfRowAfterSearch] intValue];

    if(pendingOrder == NO && todaysOrder == NO ){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:y] objectAtIndex:1]];
    }
    else if(pendingOrder == YES && todaysOrder == NO ){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:y] objectAtIndex:1]];
    }
    else
    {
        statusLabel.text = [NSString stringWithFormat:@"Status: None"];
    }
}
else{
    if(pendingOrder == NO && todaysOrder == NO){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[records objectAtIndex:indexPath.section] objectAtIndex:1]];
        NSLog(@"status lable value: %@",statusLabel.text);
    }
    else if(pendingOrder == YES && todaysOrder == NO){
        statusLabel.text = [NSString stringWithFormat:@"Status: %@",[[pendingRecords objectAtIndex:indexPath.section] objectAtIndex:1]];
    }
    else
    {
        statusLabel.text = [NSString stringWithFormat:@"Status: None"];
    }
}
return cell;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文