iOS程序设计:TableView 的基础封装-基类
2018-07-27 本文已影响0人
iOS_AllenXu
在此记录一下目前在使用的,用于快速构建一个基于tableView的列表页面的基类的简单封装,在使用的时候,只要使控制器继承该基类,实现其基本方法即可。

1、BaseSectionModel:是tableView的section的数据model,也是cellModel的Container;
2、BaseTableViewCellModel:是tableView的cell的数据model,cell也会直接根据这个cellModel的数据刷UI;
3、BaseTableViewCell: cell的基类,提供了setModel的公共方法;
4、BaseTableViewController: 控制器的基类,并add了tableView,提供了外部的一个 NSMutableArray <BaseSectionModel *>* dataSource 用于管理tableView的数据










使用时 新建控制器,CellModel, TableViewCell 分别继承于几个基类,然后在新控制器内取到数据,赋给self.dataSource,再刷UI即可(注意在cellModel中需要重写 cellClassName ,cellReuseIdentifer, rowHeight)。原理很简单,但是在传统MVC下,用起来也能节省很多代码。供新手参考。