首页 文章 精选 留言 我的

精选列表

搜索[ios],共10000篇文章
优秀的个人博客,低调大师

iOS:二叉树多级表格的使用,使用三方库TreeTableView-master实现对json解析数据的递归遍历整理成树状结构

在项目中,我们有时需要使用二叉树来实现多级表格的递归遍历查询,如果对二叉树比较懂,那么写起来其实也不费事,为了节省开发时间,下面介绍一下第三方库TreeTableView-master,这个三方库上给了一些静态的数据展示可供参考。 然而,在实际项目中,数据返回的很多都是json数据,需要自己递归遍历整理后,再将数据传递给TreeTableView作为数据源来实现多级列表。 Github下载地址:https://github.com/yixiangboy/TreeTableView 静态数据测试: //----------------------------------中国的省地市关系图3,2,1-------------------------------------------- Node *country1 = [[Node alloc] initWithParentId:-1 nodeId:0 name:@"中国" depth:0 expand:YES]; Node *province1 = [[Node alloc] initWithParentId:0 nodeId:1 name:@"江苏" depth:1 expand:NO]; Node *city1 = [[Node alloc] initWithParentId:1 nodeId:2 name:@"南通" depth:2 expand:NO]; Node *city2 = [[Node alloc] initWithParentId:1 nodeId:3 name:@"南京" depth:2 expand:NO]; Node *city3 = [[Node alloc] initWithParentId:1 nodeId:4 name:@"苏州" depth:2 expand:NO]; Node *province2 = [[Node alloc] initWithParentId:0 nodeId:5 name:@"广东" depth:1 expand:NO]; Node *city4 = [[Node alloc] initWithParentId:5 nodeId:6 name:@"深圳" depth:2 expand:NO]; Node *city5 = [[Node alloc] initWithParentId:5 nodeId:7 name:@"广州" depth:2 expand:NO]; Node *province3 = [[Node alloc] initWithParentId:0 nodeId:8 name:@"浙江" depth:1 expand:NO]; Node *city6 = [[Node alloc] initWithParentId:8 nodeId:9 name:@"杭州" depth:2 expand:NO]; //----------------------------------美国的省地市关系图0,1,2-------------------------------------------- Node *country2 = [[Node alloc] initWithParentId:-1 nodeId:10 name:@"美国" depth:0 expand:YES]; Node *province4 = [[Node alloc] initWithParentId:10 nodeId:11 name:@"纽约州" depth:1 expand:NO]; Node *province5 = [[Node alloc] initWithParentId:10 nodeId:12 name:@"德州" depth:1 expand:NO]; Node *city7 = [[Node alloc] initWithParentId:12 nodeId:13 name:@"休斯顿" depth:2 expand:NO]; Node *province6 = [[Node alloc] initWithParentId:10 nodeId:14 name:@"加州" depth:1 expand:NO]; Node *city8 = [[Node alloc] initWithParentId:14 nodeId:15 name:@"洛杉矶" depth:2 expand:NO]; Node *city9 = [[Node alloc] initWithParentId:14 nodeId:16 name:@"旧金山" depth:2 expand:NO]; //----------------------------------日本的省地市关系图0,1,2-------------------------------------------- Node *country3 = [[Node alloc] initWithParentId:-1 nodeId:17 name:@"日本" depth:0 expand:YES]; NSArray *data = [NSArray arrayWithObjects:country1,province1,city1,city2,city3,province2,city4,city5,province3,city6,country2,province4,province5,city7,province6,city8,city9,country3, nil]; TreeTableView *tableview = [[TreeTableView alloc] initWithFrame:CGRectMake(0, 20, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-20) withData:data]; tableview.treeTableCellDelegate = self; [self.view addSubview:tableview]; 结果截图显示: Github上介绍的比较详细,可以自己去看一下。 下面我来对他进行灵活的扩展,对json数据解析递归整理后,使用它利用二叉树的特点实现多级表格显示: 后台返回的json数据格式如下,每一个知识点都有自己的属性,son是用做判断是否有子知识点的条件,son1是子知识点,pid是当前知识点的父节点,knowid是当前知识点的节点,depth是当前知识点的深度等等: 2016-06-22 12:04:28.622 Point[1163:71939] { data = ( { id = 3067; knowid = 6582; name = "\U6570\U4e0e\U5f0f"; pid = 13; pidA = "0-2-13"; qNum = 123462; son = 1; son1 = ( { depth = 1; id = 3068; knowid = 6583; name = "\U6709\U7406\U6570"; pid = 6582; pidA = "0-2-13-6582"; qNum = 35487; son = 1; son1 = ( { depth = 2; id = 3069; knowid = 6584; name = "\U6709\U7406\U6570\U7684\U51e0\U4e2a\U6982\U5ff5"; pid = 6583; pidA = "0-2-13-6582-6583"; qNum = 14812; son = 1; son1 = ( { depth = 3; id = 3070; knowid = 6585; name = "\U6b63\U6570\U4e0e\U8d1f\U6570"; pid = 6584; pidA = "0-2-13-6582-6583-6584"; qNum = 2276; son = 0; url = "http://192.168.0.200//api.php/task1_2/taskadd1_2.html?id=6585&uid=12709"; }, ..................................................................... ..................................................................... 创建知识点实例KJPoint如下: // KJPoint.h // Point // Created by mac on 16/6/21. // Copyright © 2016年 mac. All rights reserved. #import <Foundation/Foundation.h> @interface KJPoint : NSObject @property (copy,nonatomic)NSString *point_depth; //知识点深度 @property (assign,nonatomic)BOOL point_expand; //知识点展开与否 @property (copy,nonatomic)NSString *point_id; @property (copy,nonatomic)NSString *point_knowid; @property (copy,nonatomic)NSString *point_name; @property (copy,nonatomic)NSString *point_pid; @property (copy,nonatomic)NSString *point_pidA; @property (copy,nonatomic)NSString *point_qNum; @property (copy,nonatomic)NSString *point_url; @property (copy,nonatomic)NSString *point_son; //作为判断是否有子节点的条件 @property (strong,nonatomic)NSArray *point_son1; //子知识点 -(instancetype)initWithPointDic:(NSDictionary *)pointDic; @end // KJPoint.m // Point // Created by mac on 16/6/21. // Copyright © 2016年 mac. All rights reserved. #import "KJPoint.h" @implementation KJPoint -(instancetype)initWithPointDic:(NSDictionary *)pointDic{ self = [super init]; if (self) { _point_id = [pointDic[@"id"] copy]; _point_depth = [pointDic[@"depth"] copy]; _point_knowid = [pointDic[@"knowid"] copy]; _point_name = [pointDic[@"name"] copy]; _point_pid = [pointDic[@"pid"] copy]; _point_pidA = [pointDic[@"pidA"] copy]; _point_url = [pointDic[@"url"] copy]; _point_qNum = [pointDic[@"qNum"] copy]; _point_son = [pointDic[@"son"] copy]; _point_son1 = pointDic[@"son1"]; } return self; } @end 创建控制器实现效果,KJPointViewController类 // ViewController.h // Point // Created by mac on 16/6/21. // Copyright © 2016年 mac. All rights reserved. #import <UIKit/UIKit.h> @interface KJPonitViewController : UIViewController @end // ViewController.m // Point // // Created by mac on 16/6/21. // Copyright © 2016年 mac. All rights reserved. // #import "KJPonitViewController.h" #import "HttpTool/KJHttpTool.h" #import "KJPoint.h" #import "TreeTableView.h" #import "Node.h" @interface KJPonitViewController ()<TreeTableCellDelegate> @property (strong,nonatomic)NSMutableArray *Points; @property (strong,nonatomic)NSMutableArray *allPoints; @end @implementation KJPonitViewController - (void)viewDidLoad { [super viewDidLoad]; //获取知识点 [self initPoints]; } -(void)initPoints{ //封装参数 _Points = [NSMutableArray array]; _allPoints = [NSMutableArray array]; NSMutableDictionary *params = [NSMutableDictionary dictionary]; params[@"uid"] = @"12709"; //用户id params[@"grade"] = @"0"; //学段:0代表初中、1代表高中//发送请求 [KJHttpTool getWithURL:Point_URL params:params success:^(id json) { NSLog(@"%@",json); [json[@"data"] enumerateObjectsUsingBlock:^(NSDictionary *pointDic, NSUInteger idx, BOOL * _Nonnull stop) { KJPoint *point = [[KJPoint alloc]initWithPointDic:pointDic]; point.point_depth = @"0"; point.point_expand = YES; [_Points addObject:point]; }]; [self recursiveAllPoints:_Points]; // //打印输出 // [_allPoints enumerateObjectsUsingBlock:^(KJPoint *point, NSUInteger idx, BOOL * _Nonnull stop) { // NSLog(@"%@____%@___%d",point.point_name,point.point_depth,point.point_expand); // }]; //创建Node节点 NSMutableArray *nodes = [NSMutableArray array]; [_allPoints enumerateObjectsUsingBlock:^(KJPoint *point, NSUInteger idx, BOOL * _Nonnull stop) { // NSLog(@"%@----%@----%@",point.point_name,point.point_knowid,point.point_pid); Node *node = [[Node alloc] initWithParentId:[point.point_pid integerValue] nodeId:[point.point_knowid integerValue] name:point.point_name depth:[point.point_depth integerValue] expand:point.point_expand]; [nodes addObject:node]; }]; //TreeTableView TreeTableView *tableview = [[TreeTableView alloc] initWithFrame:CGRectMake(0, 20, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-20) withData:nodes]; tableview.treeTableCellDelegate = self; [self.view addSubview:tableview]; } failure:^(NSError *error) { NSLog(@"%@",error); }]; } //递归所有的知识点 -(void)recursiveAllPoints:(NSMutableArray *)point_arrM{ [point_arrM enumerateObjectsUsingBlock:^(KJPoint *point, NSUInteger idx, BOOL * _Nonnull stop) { [_allPoints addObject:point]; if ([point.point_son isEqualToString:@"1"]) { NSMutableArray *sonPoints = [NSMutableArray array]; [point.point_son1 enumerateObjectsUsingBlock:^(NSDictionary *pointDic, NSUInteger idx, BOOL * _Nonnull stop) { KJPoint *point = [[KJPoint alloc]initWithPointDic:pointDic]; point.point_expand = NO; [sonPoints addObject:point]; }]; [self recursiveAllPoints:sonPoints]; } }]; } #pragma mark - TreeTableCellDelegate -(void)cellClick:(Node *)node{ NSLog(@"%@----%ld-----%ld------%ld",node.name,node.parentId,(long)node.nodeId,(long)node.depth); } @end 说明:以后不论参数怎么变,不论是三级还是四级表格,都可以自动轻松实现 效果截图如下: 提示:自己先和后台商量好如何json数据格式如何返回,目的是方便自己整理 程序猿神奇的手,每时每刻,这双手都在改变着世界的交互方式! 本文转自当天真遇到现实博客园博客,原文链接:http://www.cnblogs.com/XYQ-208910/p/5606697.html ,如需转载请自行联系原作者

优秀的个人博客,低调大师

【阿里云大学LIVE】2月28日晚8点,借你双黑客眼 透视小贝邮件门、FBI大战IOS背后的网络安全真相

秘密是个有意思的东西。 多少人可以怀揣秘密安稳过一生我们并不知道,但至少小贝是没能做到。 讲真,小贝今年挺不顺利。前些天铺天盖地的邮件门大家也都看到。简单总结,泄露邮件的主要内容有两点,一是封爵失败后爆粗,二是不愿为慈善花钱。这一记重磅炸弹让我们万人迷小贝的完美人设瞬间崩塌,众多迷妹哀嚎男神幻灭,各国键盘侠更是火力全开狂喷不止。 事实上,邮件泄露早已不是什么新鲜事儿。 去年参与美国总统竞选的希拉里更是欲哭无泪:逃过了FBI,逃过了维基解密,最终却输给了一个钓鱼邮件。 是的,惹谁,也别惹黑客。他们不光能操纵破解你的邮件,还能远程越狱你的手机控制你的iPhone。 去年美国FBI为了破解苹果iPhone 5c手机,与一家专门从事手机安全的以色列公司Cellebrite展开了合作。不过悲剧的是,日前C

优秀的个人博客,低调大师

周博通 | 阿里语音AI入选MIT“全球十大突破技术”;阿里云率先达成国家绿色数据中心标准;iOS协程开发框架coobjc开源

阿里妹导读:雪融化了,春天还会远吗? 天气渐暖,“惊蛰”将至,春雷渐来,冬眠的动物们也将陆续活动开,年后第一期的周博通也整装再发、重新上线啦,希望你会喜欢。 周 博 通 中国唯一上榜公司!阿里巴巴语音AI入选“全球十大突破性技术” 近日,阿里巴巴语音AI技术成功入选MIT2019年“全球十大突破性技术”。MIT认为,阿里巴巴已拥有世界一流的AI语音技术,可以完成复杂的人类对话功能,甚至可读懂人类的潜在意图。阿里巴巴也是唯一上榜的中国科技公司。 MIT对阿里语音助手技术的相关报道 MIT(《麻省理工科技评论》)“十大突破性技术”是全球科技领域的权威发布。它认为,之前出现的不少AI产品并没有真正做到智能,但近期的技术进展正在快速增加AI助手的功能,更智能的AI助手已经面世。阿里巴巴的AI语音助手,可以帮助消费者通过电话协调菜鸟包裹递送,还可以

优秀的个人博客,低调大师

Ios 高德地图 地图上添加多个大头针 怎么在复用队列中知道我单击的是哪一个大头针

//创建大头针对象 MAPointAnnotation*pointAnnotation=[[MAPointAnnotationalloc]init]; //插入大头针的位置 pointAnnotation.coordinate=CLLocationCoordinate2DMake(39.989631,116.481018); //大头针的标题 pointAnnotation.title=@"方恒国际"; //大头针的子标题 pointAnnotation.subtitle=@"阜通东大街6号"; [_mapViewaddAnnotation:pointAnnotation]; //实现下列方法后能让地图上得大头针弹出气泡 -(MAAnnotationView*)mapView:(MAMapView*)mapViewviewForAnnotation:(id<MAAnnotation>)annotation { if([annotationisKindOfClass:[MAPointAnnotationclass]]) { staticNSString*pointReuseIndetifier=@"pointReuseIndetifier"; MAPinAnnotationView*annotationView=(MAPinAnnotationView*)[mapViewdequeueReusableAnnotationViewWithIdentifier:pointReuseIndetifier]; if(annotationView==nil) { annotationView=[[MAPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:pointReuseIndetifier]; } annotationView.canShowCallout=YES;//设置气泡可以弹出,默认为NO annotationView.animatesDrop=YES;//设置标注动画显示,默认为NO annotationView.draggable=YES;//设置标注可以拖动,默认为NO annotationView.pinColor=MAPinAnnotationColorPurple; returnannotationView; } returnnil; } 用坐标信息判断你没说想要的具体的效果那我就给你说一种吧假设你地图上面有n个大头针实际上也就是n个pointAnnotation你可以通过_mapView.annotations直接获取到这是个数组 在点击大头针的方法里面 -(void)mapView:(BMKMapView*)mapViewdidSelectAnnotationView:(BMKAnnotationView*)view { NSArray*array=[NSArrayarrayWithArray:_mapView.annotations]; for(inti=0;i<array.count;i++) { if(view.annotation.coordinate.latitude==((BMKPointAnnotation*)array[i]).coordinate.latitude) { //获取到当前的大头针你可以执行一些操作 } else { //对其余的大头针进行操作我是删除 //[_mapViewremoveAnnotation:array[i]]; } } } 本文转自 卓行天下 51CTO博客,原文链接:http://blog.51cto.com/9951038/1764185,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码