UITableView的封装_XJTableHelper
需求
利用闲下来的这段时间,对之前的工作稍微整理一下.
首先拿到公司项目的UI,大多数的页面都是table页面,并且数目很庞大,不论开发周期的长短,如果每一个页面都要把tableView的<UITableViewDataSource>,<UITableViewDelegate>方法都重复的实现,ViewController无疑会变为处理table的垃圾桶.
UICollectionView同样适用.
git传送门:demo在这里😋
进入正题
UITableViewDataSource和UITableViewDelegate方法很多,什么值得封装?
1,tableView_required的两个方法,cellForRowAtIndexPath,numberOfRowsInSection一定要搞的
2.didSelectRowAtIndexPath点击处理也是必然要用到的,heightForRowAtIndexPath配合市场上的自适应cell高度的三方那是相当给力(定高的table不建议用,table.rowHeight能解决的问题没必要再招来麻烦)
3.拿最常规的table页面来说,多section或者多cell,定制header和footer,还有title很少遇到,个人觉得还是简单的来比较好.(不是不能做,游戏规则自己定,只是略显累赘)
上代码
第一步:需要的block,甚至不需要cell,model的传值
,后面会有介绍

第二步:初始化,这里可以根据页面的需要程度进行选择,对于极简或者稍微复杂点的页面(需要定制delegate多个方法),建议第一种,一般table页果断第二种.

第三步:目前为止还没有数据源,通常数据源都是请求到的数据,放在init里面只能传nil,很多余,不如直接了当的追加数据源.初始化既然都能细分有无delegate的回调,肯定要有相应的授权,需要我干什么我才干什么...

方法实现:
1.初始化

2.数据源处理,授权处理

3.dataSource,在这里cell直接可以performSelector配置cell,就不需要controller再做操作

4.delegate,对delegate有高要求的页面,我这只是抛砖引玉

5.UICollectionView异曲同工
应用如下
1.只处理dataSource,cell回调甚至不用写...

2.连带delegate的初始化

