图像在单元格中覆盖文本

时间:2013-06-14 23:22:05

标签: objective-c uitableview uiimageview

图像似乎覆盖了单元格中的文本,我不确定为什么会发生这种情况,但我希望文本可以覆盖图像。非常感谢任何帮助。

这就是我的代码的样子。

  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;
}

How the cells look like

1 个答案:

答案 0 :(得分:0)

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

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

并将添加的自定义imageview作为

UIImageView *imageVW=[cell viewWithTag:12345];

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