ios - UITableViewCell 显示白色背景,在 iOS7 上无法修改

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

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


即使是 Xcode7, 2015, Storyboard中也存在一个错误:您必须在代码中设置单元格的背景颜色。

最佳答案

正如 Apple DOC 所说(UITableViewCell Class Reference):

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

所以对于我的情况,要显示具有透明背景的单元格,只需要在表格 View Controller 中实现委托(delegate)方法,如下所示:

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

请注意:正如@null 所说,“...界面生成器中似乎存在错误...”,我不确定是否它确实有错误,但似乎是因为他的评论得到了几票赞成。因此,如果您使用 IB,可能会出现问题。 :)

https://stackoverflow.com/questions/18878258/

相关文章:

ios - 等到两个异步 block 被执行后再开始另一个 block

objective-c - Xcode 5 中提供了哪些新的文档命令?

iphone - @try - Objective-C 中的 catch block

objective-c - 在 Objective-C 中转换为绝对值

ios - UICollectionView 中的单元格间距

iphone - 如何在 Objective-C 中定义和使用 ENUM?

objective-c - 在 Objective-C 中,Java 的 "instanceof"关

objective-c - 在 Objective-C 中将 NSArray 转换为 NSStrin

objective-c - 禁用某些文件的自动引用计数

ios - 如何更改 UIButton 标题颜色?