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

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

问题描述

我已经实现了一个继承自 UITableViewCell 的自定义表格视图单元格类.tableview 包含一个背景图像,所以我希望单元格的背景是透明的.在 iOS7 之前看起来很棒.

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.

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

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天全站免登陆