0

图像似乎覆盖了单元格中的文本,我不确定为什么会这样,但我希望文本覆盖图像。任何帮助是极大的赞赏。

这就是我的代码的样子。

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

    CGRect imageFrame = CGRectMake(0, 0, 120, 90);
    self.customImage = [[UIImageView alloc] initWithFrame:imageFrame];
    [cell.contentView addSubview:self.customImage];
    [self.customImage release];


    CGRect contentFrame = CGRectMake(100, 2, 198, 30);
    UILabel *title = [[UILabel alloc] initWithFrame:contentFrame];
    title.tag = 0011;
    title.numberOfLines = 2;
    title.font = [UIFont boldSystemFontOfSize:12];
    [cell.contentView addSubview:title];
    [title release];

}

UILabel *title = (UILabel *)[cell.contentView viewWithTag:0011];
title.text = [currentFeed title];

NSString *directoryPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSURL *imgURL = [currentFeed thumbnailURL];
NSArray *parts = [[NSString stringWithFormat:@"%@", imgURL] componentsSeparatedByString:@"/"];
NSString *imageName = [parts objectAtIndex:[parts count]-2];

NSString *filePath = [directoryPath stringByAppendingPathComponent:imageName];

UIImage  *myview = [UIImage imageWithContentsOfFile:filePath];
if(myview){
    cell.imageView.image = myview;
}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

cell.imageView.image不是您 添加的self.customImage。现在它在单元格中显示 tableview cel 默认 imageview

self.customImage = [[UIImageView alloc] initWithFrame:imageFrame];
[cell.contentView addSubview:self.customImage];
[self.customImage setTag:12345];
[self.customImage release];

并将添加的自定义图像视图作为

UIImageView *imageVW=[cell viewWithTag:12345];

并使用此 imageview 稍后在代码中设置图像,而不是 cell.imageview

于 2013-06-15T09:34:07.637 回答