简体   繁体   English

iPhone可可:UITableViewCell背景不显示设置为IB的颜色

[英]iPhone cocoa : UITableViewCell background not displaying the color set into IB

I made a custom cell for a UITableView (subclassing UITableViewCel, e..., and with a xib). 我为UITableView制作了一个自定义单元格(将UITableViewCel继承为e ...,并带有xib)。 In IB, i set the background color of the myUITableViewCell to a light grey. 在IB中,我将myUITableViewCell的背景色设置为浅灰色。 Simulated into IB (with a run), the cell looks great (a full grey even under the disclosure button). 模拟为IB(运行),该单元看起来不错(即使在披露按钮下也为全灰色)。 But when I run the application, the cell keeps showing a white background. 但是,当我运行该应用程序时,该单元格始终显示白色背景。 Do you know why this happens ? 你知道为什么会这样吗?

May I have to do this programmaticaly to make it work ? 我是否必须以编程方式执行此操作才能使其正常工作?

Do you init the cell with initWithNibName:@"YOURXIBFILE" ...? 您是否使用initWithNibName:@“ YOURXIBFILE”来初始化单元格? Did you overwrite the drawRect Method? 您是否覆盖了drawRect方法?

yea, there is some problems to create custem cell with IB. 是的,使用IB创建客户细胞存在一些问题。

try write it in code, you can see a tutorial how to do this: 尝试用代码编写它,您可以看到一个教程如何做到这一点:

http://blog.webscale.co.in/?p=284 http://blog.webscale.co.in/?p=284

I found a great help at : Setting background color of a table view cell on iPhone 我在以下位置找到了很大的帮助: 在iPhone上设置表格视图单元格的背景色

In fact it seems that this behaviour needs coding... a very few lines, as the color set in IB is cleared at draw time. 实际上,似乎这种行为需要编码...很少的几行,因为在绘制时会清除IB中设置的颜色。 So the background color have to be set in the "willDisplayCell" tableview delegate method. 因此,必须在“ willDisplayCell”表视图委托方法中设置背景色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM