UITableViewCell-当tableview滚动时,图像消失

| 在此代码中,当我的
UITableView
是load \'lineImage时,在单元格的末尾显示图像,但是当我滚动tableview时,一些line的图像消失了,而有些保留了。有什么帮助吗?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

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


    UILabel *preferenceLabel;
    UILabel *line1Label;
    UILabel *line2Label;
    UIImageView *lineImage;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 70.0, 320.0, 2.0)];
        lineImage.contentMode = UIViewContentModeScaleAspectFit;
        lineImage.image = [UIImage imageNamed:@\"seperator bar.png\"];
        lineImage.tag = 1;
        [cell.contentView addSubview:lineImage];
        [lineImage release];

        preferenceLabel = [appDelegate newLabelWithFrame:CGRectMake(10.0, 5.0, 234.0, 20.0) PrimaryColor:[UIColor blackColor] selectedColor:[UIColor blackColor]
                                           fontSize:14.0 fontName:@\"Verdana\" bold:NO noOfLines:1];
        preferenceLabel.tag = 2;
        [cell.contentView addSubview:preferenceLabel];
        [preferenceLabel release];

        line1Label=[appDelegate newLabelWithFrame:CGRectMake(10.0,20.0,234.0,20.0) PrimaryColor:[UIColor blueColor] selectedColor:[UIColor blackColor] fontSize:14.0 fontName:@\"Verdana\" bold:NO noOfLines:1];
        line1Label.tag = 3;
        [cell.contentView addSubview:line1Label];
        [line1Label release];

        line2Label=[appDelegate newLabelWithFrame:CGRectMake(10.0,35.0,234.0,20.0) PrimaryColor:[UIColor blueColor] selectedColor:[UIColor blackColor] fontSize:14.0 fontName:@\"Verdana\" bold:NO noOfLines:1];
        line2Label.tag = 4;
        [cell.contentView addSubview:line2Label];
        [line2Label release];   

    } 
    else {
            lineImage = (UIImageView *) [cell.contentView viewWithTag:1];
            preferenceLabel = (UILabel *)[cell.contentView viewWithTag:2];
            line1Label = (UILabel *)[cell.contentView viewWithTag:3];
            line2Label = (UILabel  *)[cell.contentView viewWithTag:4];
    }


    // Configure the cell...

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 


    preferenceLabel.text = @\"Preference Label \";
    line1Label.text=@\"Line1 Label\";
    line2Label.text=@\"Line2 Label\";

    return cell;


}
    
已邀请:
当您使用[UIImage imageNamed:]时,您不必释放它,因为您无需分配自己的信息...     
您确定lineImage完全位于单元格的范围内吗? (您的rowHeight> == 72.0)如果不是,则可能是您的单元格与您的某些内容重叠并遮盖了lineImage。     
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

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


    UILabel *preferenceLabel;
    UILabel *line1Label;
    UILabel *line2Label;
    UIImageView *lineImage;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 70.0, 320.0, 2.0)];
        lineImage.contentMode = UIViewContentModeScaleAspectFit;
//removed a line of code and added at the end
        lineImage.tag = 1;
        [cell.contentView addSubview:lineImage];
        [lineImage release];

        preferenceLabel = [appDelegate newLabelWithFrame:CGRectMake(10.0, 5.0, 234.0, 20.0) PrimaryColor:[UIColor blackColor] selectedColor:[UIColor blackColor]
                                           fontSize:14.0 fontName:@\"Verdana\" bold:NO noOfLines:1];
        preferenceLabel.tag = 2;
        [cell.contentView addSubview:preferenceLabel];
        [preferenceLabel release];

        line1Label=[appDelegate newLabelWithFrame:CGRectMake(10.0,20.0,234.0,20.0) PrimaryColor:[UIColor blueColor] selectedColor:[UIColor blackColor] fontSize:14.0 fontName:@\"Verdana\" bold:NO noOfLines:1];
        line1Label.tag = 3;
        [cell.contentView addSubview:line1Label];
        [line1Label release];

        line2Label=[appDelegate newLabelWithFrame:CGRectMake(10.0,35.0,234.0,20.0) PrimaryColor:[UIColor blueColor] selectedColor:[UIColor blackColor] fontSize:14.0 fontName:@\"Verdana\" bold:NO noOfLines:1];
        line2Label.tag = 4;
        [cell.contentView addSubview:line2Label];
        [line2Label release];   

    } 
    else {
            lineImage = (UIImageView *) [cell.contentView viewWithTag:1];
            preferenceLabel = (UILabel *)[cell.contentView viewWithTag:2];
            line1Label = (UILabel *)[cell.contentView viewWithTag:3];
            line2Label = (UILabel  *)[cell.contentView viewWithTag:4];
    }


    // Configure the cell...

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    lineImage.image = [UIImage imageNamed:@\"seperator bar.png\"];//changes
    preferenceLabel.text = @\"Preference Label \";
    line1Label.text=@\"Line1 Label\";
    line2Label.text=@\"Line2 Label\";

    return cell;


}
请查看上面的代码行。我对代码进行了细微更改并进行了更新。     
地点
 lineImage.image = [UIImage imageNamed:@\"seperator bar.png\"];
之后的代码
cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    
我认为不用为分隔符添加imageview,而是通过使用它感到高兴。
mailSubscritionTable.separatorColor = [UIColor blueColor];
tableView.tableFooterView = [[[UIView alloc] init] autorelease];
    

要回复问题请先登录注册