静态 UITableViewCell backgroundColor 在 iPad 上始终为白色

Static UITableViewCell backgroundColor always white on iPad

在我的项目中,我有一个静态 TableView。我在界面生成器中更改了单元格的背景颜色。这在 iPhone.

上正确显示

但是,在 iPad 上,单元格背景始终为白色。

我找到了动态单元格的解决方案 here,但由于它使用的是 UITableViewDataSource 协议,我无法将其与我的静态单元格一起使用 table。

我该如何解决这个问题?

您应该设置 cell.contentView.backgroundColor,正如@SandeepAggarwal 指出的那样。

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

试试这个,它会解决你的问题