Unable to change background color of static table view cell on iOS 7 (iPad)

前端 未结 6 2122
礼貌的吻别
礼貌的吻别 2021-02-05 01:00

I am unable to change the background color of static UITableViewCells on iOS 7, when running on iPad device. You can easily check this with following setup:

  • Make a
6条回答
  •  孤街浪徒
    2021-02-05 02:02

    According to Apple's doc:

    Whether you use a predefined or custom cell, you can change the cell’s background using the backgroundView property or by changing the inherited backgroundColor property. 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 no matter what color you set in tableView:cellForRowAtIndexPath:, iOS 7 changes it to white later. Just set it in tableView:willDisplayCell:forRowAtIndexPath:. Worked for me perfectly.

提交回复
热议问题