ios – 在从xib加载的UITableViewHeaderFooterView上更改背景颜色说要使用contentView.backgroundColor

ios – 在从xib加载的UITableViewHeaderFooterView上更改背景颜色说要使用contentView.backgroundColor,第1张

概述我是 creating a UITableViewHeaderFooterView from a xib file,几乎一切正常. 问题是现在,当我尝试更改背景颜色(或者如果我在xib中配置了一个),它将不断地将该消息输出到控制台: Setting the background color on UITableViewHeaderFooterView has been deprecated. Pl 我是 creating a UITableViewHeaderFooterView from a xib file,几乎一切正常.

问题是现在,当我尝试更改背景颜色(或者如果我在xib中配置了一个),它将不断地将该消息输出到控制台:

Setting the background color on UItableVIEwheaderfooterVIEw has been deprecated. Please use contentVIEw.backgroundcolor instead.

这意味着我有两个问题:

>如果我不想看到这个警告,我必须摆脱xib文件中的背景颜色(这是不希望的,因为这意味着我的xib不再反映在运行时视图的外观).
>当我尝试通过代码更改背景颜色时,我得到contentVIEw.backgroundcolor的建议,但是当我尝试遵循这个建议,没有任何反应. (这是因为contentVIEw为零)

注意:这里有一个similar question,但主要是关于静音消息,没有找到一个解决上述两个问题的替代解决方案.

更新:要清楚,我想继续使用头文件视图的xib文件,并希望能够调用dequeueReusableHeaderFooterViewWithIdentifier:,以便在管理视图时该表可以是高效的.

解决方法 这是找到解决这个问题的最好方法:

>将UItableVIEwheaderfooterVIEw的背景颜色重置为默认值.
>直接在UItableVIEwheaderfooterVIEw的实例下面添加一个视图,并将其称为“内容视图”. (这正是苹果与UItableVIEwCell做的,我们只是模仿那个结构.)
>现在,您可以将内容视图的背景颜色更改为xib文件中所需的任何内容.
>将任何其他视图放在内容视图中.
>在扩展方法中重新定义contentVIEw属性,并将IBOutlet添加到其定义中. (见下面的代码.)
>将属性与您创建的内容视图相关联,就像使用任何IBOutlet一样.
>您现在可以使用contentVIEw.backgroundcolor在代码中更改背景颜色,就像错误消息一样.

.h文件:

@interface ABCheaderVIEw : UItableVIEwheaderfooterVIEw@end

.m文件:

@interface ABCheaderVIEw ()@property (nonatomic,reaDWrite,retain) IBOutlet UIVIEw *contentVIEw;@end@implementation ABCheaderVIEw@synthesize contentVIEw;@end

这种层次结构与Apple’s documentation是一致的:

If you have custom content to display,create the subvIEws for your content and add them to the vIEw in the contentVIEw property.

总结

以上是内存溢出为你收集整理的ios – 在从xib加载的UITableViewHeaderFooterView上更改背景颜色说要使用contentView.backgroundColor全部内容,希望文章能够帮你解决ios – 在从xib加载的UITableViewHeaderFooterView上更改背景颜色说要使用contentView.backgroundColor所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1112481.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存