【发布时间】:2016-10-17 16:47:48
【问题描述】:
在使用UITableView 和UICollectionView 时,我正在研究编写模块化干净代码,我发现Objc.io 写的关于编写更轻量级视图控制器的不错的博客。在遵循作者给出的做法时,我想出了一段关于Same Cell type and Multiple Model Object 的内容,但没有详细说明,只是描述性的。
我只是想问有没有人建议我们如何以更好的模块化方式实现这一目标?
这段话是这样说的,
In cases where we have multiple model objects that can be presented using the same cell type, we can even go one step further to gain reusability of the cell. First, we define a protocol on the cell to which an object must conform in order to be displayed by this cell type. Then we simply change the configure method in the cell category to accept any object conforming to this protocol. These simple steps decouple the cell from any specific model object and make it applicable to different data types.
谁能解释一下这是什么意思? 我知道这不是主题,但它可能会帮助某人编写更好的代码。
【问题讨论】:
标签: ios uitableview design-patterns model-view-controller uicollectionview