美文网首页
我的开源-自定义树形结构-YPTreeView

我的开源-自定义树形结构-YPTreeView

作者: 踩了个铺 | 来源:发表于2016-07-06 15:04 被阅读213次

树形结构视图,数据源无顺序要求,自动构建树结构。

支持多选单选,支持改各种颜色。


使用示例:

- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor=[UIColor lightGrayColor];

// Do any additional setup after loading the view, typically from a nib.

self.treeView=[[YPTreeView alloc]initWithFrame:CGRectMake(0, 40,self.view.frame.size.width, self.view.frame.size.height-80)];

//支持多选

self.treeView.isCanMultipleChoice=YES;

self.treeView.delegate=self;

self.treeView.lineColor=[UIColor blackColor];

self.treeView.textColor=[UIColor blackColor];

self.treeView.backgroundColor=[UIColor colorWithRed:242/255.0 green:249/255.0 blue:255/255.0 alpha:1];

[self.view addSubview:self.treeView];

//可以异步 接口返回数据后赋值

self.treeView.dataArray=[self getDataArray];

}

其使用的数据源需要为NSArray<YPTreeNode>

数据例子:

-(NSArray *)getDataArray{

NSMutableArray * threeDataSoure=[NSMutableArray array];

YPTreeNode *treedata=[[YPTreeNode alloc]init];

treedata.name=@"根节点";

treedata.treeId=@"1";

treedata.parentId=@"0";

treedata.value=@"root";

treedata.isOpen=YES;

[threeDataSoure addObject:treedata];

YPTreeNode *treedata2=[[YPTreeNode alloc]init];

treedata2.name=@"第一章";

treedata2.treeId=@"3";

treedata2.parentId=@"1";

treedata2.value=@"first";

treedata2.isOpen=YES;

[threeDataSoure addObject:treedata2];

YPTreeNode *treedata3=[[YPTreeNode alloc]init];

treedata3.name=@"第二章";

treedata3.treeId=@"2";

treedata3.parentId=@"1";

treedata3.value=@"second";

treedata3.isOpen=YES;

[threeDataSoure addObject:treedata3];

YPTreeNode *treedata4=[[YPTreeNode alloc]init];

treedata4.name=@"第一节 iOS简介";

treedata4.treeId=@"5";

treedata4.parentId=@"3";

treedata4.value=@"second";

treedata4.isOpen=YES;

[threeDataSoure addObject:treedata4];

YPTreeNode *treedata5=[[YPTreeNode alloc]init];

treedata5.name=@"第一节 TableView的使用";

treedata5.treeId=@"4";

treedata5.parentId=@"2";

treedata5.value=@"TableView";

treedata5.isOpen=YES;

[threeDataSoure addObject:treedata5];

return threeDataSoure;

}


demo下载

git地址:   YPTreeView-master


集成

pod 'YPTreeView'


效果如下图:

相关文章

  • 我的开源-自定义树形结构-YPTreeView

    树形结构视图,数据源无顺序要求,自动构建树结构。 支持多选单选,支持改各种颜色。 使用示例: - (void)vi...

  • SpringMVC+ZTree实现树形菜单权限配置

    计划在开源项目里加入权限配置的功能,打算加入zTree实现树形结构。 Team的Github开源项目链接:http...

  • js 数组与树形结构对象相互转换

    数组 树形结构对象 数组转成树形结构 树形结构转成数组

  • 【恋上数据结构与算法一】(六)二叉树

    二叉树 线性结构 树形结构 二叉树 多叉树 生活中的树形结构 ◼ 使用树形结构可以大大提高效率◼ 树形结构是算法面...

  • 十、二叉树(Binary Tree)

    1、树形结构 之前所讲的那些数组、链表、栈、队列等都是线性结构。 下面就是树形结构: 为什么要用到树呢?使用树形结...

  • 树形结构(一):二叉树

    树形结构是指数据元素之间存在“一对多”(One-to-Many)的树形对应关系而形成的一类数据结构,树形结构是一类...

  • java 数据库树形结构的各种取值

    数据库中存的数据结构:id和parent_id 需求: 得到一个树形结构的json数据 自定义获取到某一级,得到树...

  • 树形结构

    树是一种分层数据的抽象模型。它和散列表一样是一种非顺序数据结构,它对于存储需要快速查找的数据非常有用。 树的相关术...

  • 树形结构

    数据结构中的元素存在一对多的相互关系 二叉树 2. 非二叉树 3. 自平衡二叉查找树 4. B树 5. Trie ...

  • 树形结构

    今天听到门卫回答一路人关于核酸检测何时结束的问题,门卫说,他们也没有收到通知,不知道几点结束。 我眼前顿时浮现了一...

网友评论

      本文标题:我的开源-自定义树形结构-YPTreeView

      本文链接:https://www.haomeiwen.com/subject/fmwddttx.html