UITableViewCell显示白色背景,不能在iOS7上修改 [英] UITableViewCell show white background and cannot be modified on iOS7

查看:116
本文介绍了UITableViewCell显示白色背景,不能在iOS7上修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个自定义的表视图单元格类继承自 UITableViewCell 。 tableview包含一个背景图片,所以我想要单元格的背景是透明的。

I've implemented a custom table view cell class that inherit from UITableViewCell. The tableview contains a background image, so I want cell's background to be transparent. It looks great before iOS7.

但是,在iOS7中,单元格总是以白色背景显示。

However, in iOS7, the cell is always shown with a white background.

即使对于Xcode7,2015,是故事板中的错误:您必须在代码中设置单元格的背景颜色。

Even for Xcode7, 2015, there is a bug in storyboard: you have to set the background color of a cell in code.

推荐答案

正如Apple DOC所说(UITableViewCell类参考):

As Apple DOC said (UITableViewCell Class Reference):


... 在iOS 7中,单元格默认为白色背景;在早期版本的iOS中,单元格继承了封闭表视图的背景颜色。如果您要更改单元格的背景颜色,请在表视图代理的 tableView:willDisplayCell:forRowAtIndexPath: 方法中进行。

... In iOS 7, cells have a white background by default; in earlier versions of iOS, cells inherit the background color of the enclosing table view. If you want to change the background color of a cell, do so in the tableView:willDisplayCell:forRowAtIndexPath: method of your table view delegate.

所以对于我的情况,为了显示具有透明背景的单元格,只需要在表视图控制器中实现delegate方法,如下所示:

So for my case that to show cells with transparent background, just need to implement the delegate method in the table view controller like below:

- (void)tableView:(UITableView *)tableView
  willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
  [cell setBackgroundColor:[UIColor clearColor]];
}






:正如@null所说,...在界面生成器中似乎有一个错误...,我不完全确定它是否有错误,但似乎所以导致他的评论有几个投票。所以如果你使用IB可能会出错。 :)


Just Note: As @null said, "...there seems to be a bug in interface builder...", I'm not totally sure whether it does have the bug, but seems so cause his comment got several up votes. So there might something wrong if you use IB. :)

这篇关于UITableViewCell显示白色背景,不能在iOS7上修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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