单元格中的文本重复并且在我滚动[图像]之前不显示

时间:2013-06-14 11:21:37

标签: objective-c uitableview

所以我在tableView中加载了一个YouTube频道并尝试添加正确的持续时间,但有时它根本没有显示,如果它确实显示,如果仔细观察,它背后会有另一个文字。

当您查看图像1时,您可以看到一个视频上没有时间,直到我滚动它。

当您查看图像2时,您可以看到文本标签在某些地方重复

代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";
ChanelFeeds *currentFeed = [[xmlParser feeds] objectAtIndex:indexPath.row];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];


totalTime = [self timeFormatted:([currentFeed duration].intValue)-1];
    if([totalTime length] <= 4) {

        CGRect contentFrame6 = CGRectMake(0, 66, 30, 13);
        CGRect contentFrame7 = CGRectMake(6, 65, 60, 15);
        UILabel *title3 = [[UILabel alloc] initWithFrame:contentFrame7];
        UIImageView *imv5 = [[UIImageView alloc]initWithFrame:contentFrame6];

        imv5.image=[UIImage imageNamed:@"blackBorder.png"];
        imv5.alpha = 0.8;
        [cell.contentView addSubview:imv5];

        title3.tag = 0013;
        title3.numberOfLines = 1;
        title3.font = [UIFont boldSystemFontOfSize:10];
        [cell.contentView addSubview:title3];
        title3.text = totalTime;
        title3.textColor = [UIColor whiteColor];
        title3.backgroundColor = [UIColor clearColor];
        imv5.backgroundColor = [UIColor clearColor];
        [imv5 release];
        [title3 release];
    } else if([totalTime length] == 5) {
        CGRect contentFrame6 = CGRectMake(87, 64, 30, 13);
        CGRect contentFrame7 = CGRectMake(90, 63, 60, 15);
        UILabel *title3 = [[UILabel alloc] initWithFrame:contentFrame7];
        UIImageView *imv5 = [[UIImageView alloc]initWithFrame:contentFrame6];

        imv5.image=[UIImage imageNamed:@"blackBorder.png"];
        imv5.alpha = 0.8;
        [cell.contentView addSubview:imv5];

        title3.tag = 0013;
        title3.numberOfLines = 1;
        title3.font = [UIFont systemFontOfSize:10];
        [cell.contentView addSubview:title3];
        title3.text = totalTime;
        title3.textColor = [UIColor whiteColor];
        title3.backgroundColor = [UIColor clearColor];
        imv5.backgroundColor = [UIColor clearColor];
        [imv5 release];
        [title3 release];
    }

}else{
    NSData* imageDataTemp = [[NSData alloc] initWithContentsOfURL:[currentFeed thumbnailURL]];
    if(imageDataTemp){
        cell.imageView.image = [UIImage imageWithData:imageDataTemp];
    }else{
        cell.imageView.image = [UIImage imageNamed:@"youtubeLogo.png"];
    }


}

return cell;

}

No duration at all Text label on cell duplicating

1 个答案:

答案 0 :(得分:0)

可能会改变它 -

if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

然后,阻止 -

totalTime = [self timeFormatted:([currentFeed duration].intValue)-1];
    if([totalTime length] <= 4) {

        CGRect contentFrame6 = CGRectMake(0, 66, 30, 13);
        CGRect contentFrame7 = CGRectMake(6, 65, 60, 15);
        UILabel *title3 = [[UILabel alloc] initWithFrame:contentFrame7];
        UIImageView *imv5 = [[UIImageView alloc]initWithFrame:contentFrame6];

        imv5.image=[UIImage imageNamed:@"blackBorder.png"];
        imv5.alpha = 0.8;
        [cell.contentView addSubview:imv5];

        title3.tag = 0013;
        title3.numberOfLines = 1;
        title3.font = [UIFont boldSystemFontOfSize:10];
        [cell.contentView addSubview:title3];
        title3.text = totalTime;
        title3.textColor = [UIColor whiteColor];
        title3.backgroundColor = [UIColor clearColor];
        imv5.backgroundColor = [UIColor clearColor];
        [imv5 release];
        [title3 release];
    } else if([totalTime length] == 5) {
        CGRect contentFrame6 = CGRectMake(87, 64, 30, 13);
        CGRect contentFrame7 = CGRectMake(90, 63, 60, 15);
        UILabel *title3 = [[UILabel alloc] initWithFrame:contentFrame7];
        UIImageView *imv5 = [[UIImageView alloc]initWithFrame:contentFrame6];

        imv5.image=[UIImage imageNamed:@"blackBorder.png"];
        imv5.alpha = 0.8;
        [cell.contentView addSubview:imv5];

        title3.tag = 0013;
        title3.numberOfLines = 1;
        title3.font = [UIFont systemFontOfSize:10];
        [cell.contentView addSubview:title3];
        title3.text = totalTime;
        title3.textColor = [UIColor whiteColor];
        title3.backgroundColor = [UIColor clearColor];
        imv5.backgroundColor = [UIColor clearColor];
        [imv5 release];
        [title3 release];
    }

}else{
    NSData* imageDataTemp = [[NSData alloc] initWithContentsOfURL:[currentFeed thumbnailURL]];
    if(imageDataTemp){
        cell.imageView.image = [UIImage imageWithData:imageDataTemp];
    }else{
        cell.imageView.image = [UIImage imageNamed:@"youtubeLogo.png"];
    }


}

然后, - return cell;

设置,即第二个块应该每次一个单元格dequed,而不仅仅是在分配新的时候。