【问题标题】:moving up problem in custom table view cell在自定义表格视图单元格中向上移动问题
【发布时间】:2010-07-08 05:02:42
【问题描述】:

我正在使用自定义表格视图单元格显示到表格视图

- (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 语句结果

提前致谢

问候, 萨蒂什

【问题讨论】:

    标签: iphone uitableview scroll


    【解决方案1】:

    这样做的原因是单元格被重复使用,您需要在 if 的 else 中重置该图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      相关资源
      最近更新 更多