前言
参考了原作者 @格式化油条
http://www.cnblogs.com/geshihuayoutiao/p/4671246.html
基于Masonry与UITableView+FDTemplateLayoutCell搭配使用
而自己一直习惯使用Purelayout的框架,因此把项目改写用Purelayout使用。
介绍
Purelayout是一款轻量级的布局框架,上手简单。
FDTemplateLayoutCell 是一款tableview cell高度自动计算的布局框架。
本文只是对此的结合使用,具体源码:
Purelayout Github地址 : https://github.com/PureLayout/PureLayout
UITableView-FDTemplateLayoutCell github:https://github.com/forkingdog/UITableView-FDTemplateLayoutCell
代码详解
进入正题:(本文素材是来自阳神的demo里面的。阳神用的是storyboard实现,而我是用PureLayout实现)
1.首先在子线程解析JSON数据
2.然后返回主线程注册cell,并且刷新tableView
3.在cellForRowAtIndexPath的方法中抽出一个方法,给cell的模型赋值。
UITableView+FDTemplateLayoutCell 这个类有两种模式,一种是使用自动布局,一种则是计算frame的形式。
4.接下来我们看下自定义cell里面的实现。
在初始化的方法内部创建子控件并且使用PureLayout布局
5.布局方法实现
6.重新返回控制器中,实现tableview的heightForRowAtIndexPath方法,在其内部重新给cell的模型赋值
本文demo:
https://github.com/xinGGG/FDTemplateLayoutCell-PureLayout
Demo截图: