UIView 可重用性

Posted

技术标签:

【中文标题】UIView 可重用性【英文标题】:UIView reusability 【发布时间】:2016-02-17 11:25:57 【问题描述】:

我有两个 ViewController - FirstViewControllerSecondViewControllerFirstViewController 有一个 tableViewcustomTableViewCells。每个cell 都有动态内容。选择后,用户被带到SecondViewController

SecondViewController 是所选cell 的详细表示。在SecondViewController 中,我有一个bannerView,它与FirstViewController 选择的cellcontentView 相同。它完美地工作。

但问题是,我再次在SecondViewControllerbannerView 中重新创建整个FirstViewControllercellcontentView。我只是怀疑是否可以在不重新创建SecondViewController 的情况下重用contentView。欢迎提出想法。

【问题讨论】:

继续为它创建一个 xib 文件。随心所欲地加载它。 【参考方案1】:

扩展 UIView 类以创建您的自定义视图并将其作为子视图添加到单元格的内容视图。

【讨论】:

以上是关于UIView 可重用性的主要内容,如果未能解决你的问题,请参考以下文章