【发布时间】:2011-10-30 16:31:50
【问题描述】:
[已修复] 在尝试了很多不同的解决方案后,我终于找到了一个工作。我需要做的就是在 willDisplayCell 方法中将单元格背景颜色设置为清除:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
[cell setBackgroundColor:[UIColor clearColor]];
我的 UITableview 有一张背景图片(照片),表格视图中的单元格有一个半透明的背景。
当我第一次显示 UITableView 时,单元格没有显示为透明。但是,当我将一个单元格滚动出屏幕并将其滚动回具有半透明背景的单元格显示时。
有没有人知道为什么在单元格滚动到屏幕外之前它不能正确显示?见附图。第一个在加载后立即显示 tableview。第二张图片显示了将顶部的几个单元格从屏幕上滚动并重新打开后的样子。
下面是我用来设置单元格的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellPhotoIdentifier = @"PhotoDescriptionCell";
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellPhotoIdentifier] autorelease];
// Configure the cell...
cell.textLabel.text = [NSString stringWithFormat:@"Photo description %i", indexPath.row];
cell.textLabel.textColor = [UIColor whiteColor];
cell.opaque = NO;
cell.contentView.backgroundColor = [UIColor blackColor];
cell.contentView.opaque = NO;
cell.contentView.alpha = 0.7;
cell.textLabel.backgroundColor = [UIColor clearColor];
return cell;
}
我正在使用 XCode 4 和 IOS SDK 4.3
【问题讨论】:
-
我之前尝试过,我尝试在 willDisplayCell 函数中设置透明度,但它仍然不起作用。但是我又试了一次,只是将单元格背景颜色设置为 [UIColor clearColor] 并且它现在可以工作了。
标签: iphone cocoa-touch uitableview