0

因此,我在 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;

}

完全没有持续时间 单元格复制上的文本标签

4

1 回答 1

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,而不仅仅是在分配新单元格时。

于 2013-06-14T11:27:35.717 回答