半透明的UITableViewCells是不透明的,直到他们已经滚动离开屏幕 [英] Semi-Transparent UITableViewCells are not transparent until they have been scrolled off screen

查看:207
本文介绍了半透明的UITableViewCells是不透明的,直到他们已经滚动离开屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[FIXED]
在尝试了很多不同的解决方案后,我终于有了一个工作。我需要做的是设置单元格backgroundColor在willDisplayCell方法中清除:

[FIXED] After trying quite a few different solutions I finally got one to work. All I needed to do was set the cell backgroundColor to clear in the willDisplayCell method:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

[cell setBackgroundColor:[UIColor clearColor]];

我的UITableview有一个背景图片(照片),表格视图中的单元格有半透明背景。

My UITableview has a background image (Photo) and the cells in the table view have a semi-transparent background.

当我第一次显示UITableView时,单元格没有显示为透明。但是,一旦我将一个单元格从屏幕上滚动出来,并在半透明背景的单元格显示上滚动它。

When i first show the UITableView the cells are not showing as transparent. But as soon as I scroll a cell off screen and scroll it back on the cell displays with the semi-transparent background.

有没有人有任何线索,为什么它显示正确,直到单元格滚动离开屏幕?参见附图。第一个显示tableview一加载。而第二张图片显示的是将顶部几个单元格从屏幕上滚动并重新开始后的样子。

Does anyone have any clues as to why it doesn't display correctly until the cell is scrolled off screen? See attached images. First one shows the tableview as soon as its loaded. and the second image shows what it looks like after scrolling the top few cells off screen and back on again.


是我用来设置单元格的代码。

Below is the code I'm using to setup the cell.

- (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

I'm using XCode 4 with IOS SDK 4.3

推荐答案

重新阅读@progrmr给出的链接的答案后,我再次尝试并设法使其工作。

After re-reading the answer that @progrmr gave the link for, I tried again and managed to get it to work.

我需要在 willDisplayCell 方法中设置要清除的单元格背景颜色

I needed to set the Cell Background Color to clear in the willDisplayCell method

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

[cell setBackgroundColor:[UIColor clearColor]];

[cell setBackgroundColor:[UIColor clearColor]];

这篇关于半透明的UITableViewCells是不透明的,直到他们已经滚动离开屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆