UITableView backgroundColor is always white on iPad

I'm working on the project. I have many UITableView that are set as pure color. The background color of their views is set to my custom color, and everything is fine on the iPhone .

The problem occurs on the iPad ! I tried almost everything, but my UITableView is white.

I checked other topics, for example: UITableView backgroundColor is always gray on the iPad , but nothing worked. In addition, my problem is not gray, it is white as snow!

What could be the reason for this?

+67
ios objective-c uitableview ipad uibackgroundcolor
Dec 18 '14 at 16:28
source share
16 answers

Good News: According to iOS 10 Release Notes:

When working on an iPad, the background color set for the UITableViewCell in the storyboard is now respected.

For versions <10:

I saw this in iOS 8 (8.3). Despite the fact that in IB my cells were “clear color” and their content views were “clear color”, they would display as white. Inadequate but reasonable solution, as it still takes values ​​from IB:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... cell.backgroundColor = cell.contentView.backgroundColor; return cell; } 

It seems that my deleted reusable cells make their background white on the iPad. I was able to determine this using the view hierarchy debugger.

As soon as I did this, I managed to use the background color of the table and did not have to set the background view, although this also works.

+111
May 31 '15 at 19:11
source share

You can fix this by setting the appearance API in the appDelegate file:

Swift:

 UITableViewCell.appearance().backgroundColor = UIColor.clearColor() 
+32
Feb 03 '16 at 6:22
source share

Instead of setting the background color, try using the background mode instead, for example:

 - (void)viewDidLoad { self.tableView.backgroundView = [UIView new]; self.tableView.backgroundView.backgroundColor = [UIColor clearColor]; } 

I had problems when using backgroundColor does not always work, but setting the background view works fine.

+19
Dec 19 '14 at 8:40
source share

Creating Ben Flynn's answer ... cell.contentView The background color is not necessarily equal to the color of cell.background. In this case, I found that this worked in solving the iPad white background issue in the following situations:

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... cell.backgroundColor = cell.backgroundColor; return cell; } 

As long as the statement looks ridiculous and crazy ... this solves the problem.

+12
Jun 17 '15 at 10:18
source share

I have a tabular view with many different cells inside, each of which has a different color.

Reply from @Ben Flynn cell.backgroundColor = self.contentView.backgroundColor cannot achieve this. The reason is that self.contentView.backgroundColor is zero, so what you did is just clear cell.backgroundColor = nil .

This is mainly a bug from Xcode (I think yes, it sucks!), cell.backgroundColor still has color, but it cannot be displayed.

After debugging for a while, based on @Ray W's answer, here is my solution.

 @impelement YouCustomCellClass - (void)awakeFromNib { [super awakeFromNib]; self.backgroundColor = self.backgroundColor; // What the heck?? But it is. } @end 
+10
Nov 28 '15 at 1:48
source share

In my experience, some versions of iOS set UITableViewCell backgroundColor before calling the delegate tableView:willDisplayCell:forRowAtIndexPath: Resetting back to your custom color in this method corrects it.

+3
Dec 19 '14 at 7:53 on
source share

This solves this problem for me

  func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { tableView.backgroundColor = UIColor.clear } 
+3
Feb 28 '17 at 8:25
source share

SWIFT 3.XX

Put it

 UITableViewCell.appearance().backgroundColor = UIColor.clear 

In AppDelegate

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
+2
Aug 11 '17 at 7:15
source share

I use Storyboard with UITableViewControlrs , so the easiest solution was to subclass all the controllers and add this method to the parent

 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){ cell.backgroundColor = [UIColor clearColor]; } } 
+1
Nov 19 '15 at 11:17
source share

SWIFT

It happened to me. My table in my SWRevealViewController turned white on my iPad when it looked clear (as I wanted it with the background image) on my iPhone. I tried all of the above, but this is what ended up working for me in my view of DidLoad ().

 tableView.backgroundView = UIImageView(image: UIImage(named: "gray")) tableView.backgroundView?.backgroundColor = .clearColor() UITableViewCell.appearance().backgroundColor = .clearColor() 
+1
Jun 24 '16 at 18:01
source share

Swift 3.1

I worked on this error by placing it in my subclass of UITableViewCell :

When a cell is loaded from a NIB file:

 override func awakeFromNib() { super.awakeFromNib() self.backgroundColor = UIColor.clear } 

and when the cell is reused by the system

 override func prepareForReuse() { super.prepareForReuse() self.backgroundColor = UIColor.clear } 

iOS 10 should fix this problem in Interface Builder, as animeshporwal said.

+1
Sep 07 '16 at 10:58
source share

This can be achieved in the storyboard as follows:

  • Show document layout for storyboard
  • In your table, select TableViewCell
  • go to the content view inside this cell
  • Set the background color in the Content view.

Result: iPad and iPhone simulations look the same

0
Dec 13 '15 at 11:33
source share

I had this problem and fixed it by changing the backgroundColor View (as opposed to the TableView table). It looks like the iPad, the one that is used first, and in my case it was set to white.

0
Dec 28 '15 at 23:16
source share

SWIFT I also had this problem. Works great on .phone, but tableViewCells goes white on .pad. Thought I'd show how I fixed it with a quick one.

Connect the TableViewCell to viewController.swift as @IBOutlet, for example:

  @IBOutlet weak var tvc1: UITableViewCell! @IBOutlet weak var tvc2: UITableViewCell! @IBOutlet weak var tvc3: UITableViewCell! 

Then in viewDidLoad enter the following:

 tvc1.backgroundColor = tvc1.backgroundColor tvc2.backgroundColor = tvc2.backgroundColor tvc3.backgroundColor = tvc3.backgroundColor 

Very strange, I don’t know what is going on here, but it solved it for me.

0
Apr 07 '16 at 2:11
source share

This is similar to a fix with iOS 10 Beta 4, as stated in the release notes in the UIKit notes:

enter image description here

0
Aug 08 '16 at 18:35
source share

I have a transparent table view with translucent table view cells. When I create the table, I set the background color of the table. This works for all iOS / device combinations except iPad + iOS 8, where the background color remains white.

For me, setting the background color of the cell to translucent, and the background color of the content view for cleaning works, since I do this on every tableView(_ tableView: UITableView, cellForRowAt indexPath) . The problem for me was only that the background in the form of a table remained white.

I tried all the combinations that I found on this problem, but the only thing I really needed was to set the table background transparency on each tableView(_ tableView: UITableView, cellForRowAt indexPath) . Not superintuitive, but at least it works .: P

0
Nov 14 '16 at 9:56
source share



All Articles