谁能告诉我为什么tableview数据直到滚动才显示?

时间:2011-12-29 04:05:47

标签: iphone ios uitableview uilabel

在我的tableview中,我设置了要显示的xml数据,但在滚动之前它不会显示所有值。我在获取xml数据时重新加载了tableview。我也使用了[cell.contenView viewWithTag:tagnumber];但是现在还没有工作......请帮助我任何人......

数据即将到来并使用NSLog我可以获取值,但在滚动之前不会显示。 有人认为我必须提到我可以看到我的cellview和imageview,但没有显示标签数据。

 - (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;
}

滚动表格之前。

enter image description here

滚动表格视图后

enter image description here

1 个答案:

答案 0 :(得分:0)

在每种情况下都不需要以下代码,因为您已经在条件之外编写了代码。这似乎重复。

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

在回答您的问题时,最初似乎会跳过ifelse if条件。同时评论NSLog并在NSLog部分条件中写下else

修改

//  [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;