在IOS开发中,很多时候项目需求会有点击某一行,展开cell下面的cell,在此点击会收起;
这种实现方式很多,个人这里随便推荐一种实现方式:
1、在数据转模型的model里面添加一个属性,@property(assign,nonatomic)BOOL isOpen;//是否展开
2、在对应的tableView层,- (nullableUIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section;方法下面生成View,并未其添加点击事件;点击事件方法如下:

在对应的tableView的dataSource方法中:

以及- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{ if(self.dataList[indexPath.section].isOpen) {
if(self.dataList[indexPath.section].isOpen) {
//设置展开的cell
}else{
//设置没有展开的cell;
}}
上面只能实现二级展开,很多时候会遇到三级展开,那上面的想法就不能实现了(只是我不能实现,如有大神可以实现,还请指点一下);如果是三级展开,推荐一个框架:RATreeView
实现的方法和tableBView差不多,实现他的几个代理方法:

解释一下:传进来的item:代表他给你的model,根据这个model可以去获取上级model: clickpackagesModel*packageModel = [treeViewparentForItem:model];
同样可以根据model获取相应的cell: clickPackageCell*packagecell01 = (clickPackageCell*)[treeViewcellForItem:model];
有了上面两个方法,基本就能玩转三级展开和收起;


对于三级展开,大家还有什么好的想法亦或者好的框架没?欢迎补充
网友评论