提升自定义表格视图单元格中的问题

时间:2010-07-08 05:02:43

标签: iphone uitableview scroll

我使用自定义表格视图单元格来显示表格视图

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier 
{
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) 
{
     m_mail_status = [[UIImageView alloc] initWithFrame:CGRectMake(295, 10, 18, 18)];
    [self addSubview:m_mail_status];

    m_subject = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 270, 37)];
    UIFont* font = m_subject.font;

    m_subject.font = [UIFont boldSystemFontOfSize:font.pointSize];

    //m_subject.font = [UIFont systemFontOfSize:17];
    [self addSubview:m_subject];

    m_from = [[UILabel alloc] initWithFrame:CGRectMake(10, 37, 200, 15)];
    m_from.font = [UIFont systemFontOfSize:12];
    [self addSubview:m_from];

    m_date = [[UILabel alloc] initWithFrame:CGRectMake(180, 37, 140, 15)];
    m_date.textAlignment= UITextAlignmentRight;
    m_date.font = [UIFont systemFontOfSize:12];
    [self addSubview:m_date];




}
return self;
}

和我在视图控制器中的代码,

static NSString *MyIdentifier = @"ProductsCell";
InboxViewCell *cell = (InboxViewCell*)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];

//static NSString *CellIdentifier = @"Cell";

// UITableViewCell *cell = nil;// [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"xx"] autorelease];


if(cell == nil) 
    cell = [[[InboxViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];


    cell.m_subject.text = [[inbox objectAtIndex:indexPath.row] objectForKey:@"subject"];
    cell.m_from.text = [[inbox objectAtIndex:indexPath.row] objectForKey:@"from"];
    cell.m_date.text = [[inbox objectAtIndex:indexPath.row] objectForKey:@"date"];

    if([[[inbox objectAtIndex:indexPath.row] objectForKey:@"**reservation_status**"] isEqualToString:@"1"])     
    {
    cell.m_mail_status.image =  [UIImage imageNamed:@"reservation_symbol.png"];
    }

首次加载时以正确方式加载 当我向下滚动并向上移动时的问题 显示所有图像忽略if语句结果

提前致谢

此致 sathish

1 个答案:

答案 0 :(得分:0)

原因是细胞被重复使用,您需要在if的其他位置重置该图像。