美文网首页
GDataXMLElement解析多分区

GDataXMLElement解析多分区

作者: 法库德 | 来源:发表于2017-09-19 08:27 被阅读0次

#import "GDataXMLNode.h"

{

NSMutableDictionary *dic;

UITableView *tab;

}

# define MAC @"http://127.0.0.1/LOL.xml"

{

[super viewDidLoad];

//

NSURL *url=[NSURL URLWithString:MAC];

NSURLSession * see=[NSURLSession sharedSession];

NSURLSessionDataTask *tas=[see dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

//创建对象

GDataXMLDocument *the=[[GDataXMLDocument alloc]initWithData:data options:0 error:nil];

//获取跟标签

GDataXMLElement *rootel=[the rootElement];

//初始化字典

dic=[[NSMutableDictionary alloc]init];

for (GDataXMLElement *sor in [rootel elementsForName:@"a"])

{

NSString *key=[[sor attributeForName:@"king"]stringValue];

NSMutableArray *arr=[[NSMutableArray alloc]init];

//给数组添加数据

for (GDataXMLElement *hfenelem in [sor elementsForName:@"fen"])

{

Model *mo=[[Model alloc]init];

mo.name=[[[hfenelem elementsForName:@"name"]firstObject]stringValue];

mo.age=[[[hfenelem elementsForName:@"age"]firstObject]stringValue];

[arr addObject:mo];

}

//给字典赋值

[dic setObject:arr forKey:key];

}

//回到主线程刷新表格

dispatch_async(dispatch_get_main_queue(), ^{

//刷新表格

[tab reloadData];

});

}];

[tas resume];

tab=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];

tab.delegate=self;

tab.dataSource=self;

[self.view addSubview:tab];

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return dic.count;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

{

NSString *key=[dic.allKeys objectAtIndex:section];

return [[dic objectForKey:key]count];

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *str=@"cell";

UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];

if (cell==nil)

{

cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];

}

NSString *key=[dic.allKeys objectAtIndex:indexPath.section];

cell.textLabel.text=[[[dic objectForKey:key]objectAtIndex:indexPath.row]name];

cell.detailTextLabel.text=[[[dic objectForKey:key]objectAtIndex:indexPath.row]age];

return cell;

}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

return [dic.allKeys objectAtIndex:section];

}

相关文章

  • GDataXMLElement解析多分区

    #import "GDataXMLNode.h" { NSMutableDictionary *dic; UITa...

  • ios 分区解析

    继承Object .h 写文本属性 名 #import "ViewController.h" #import ...

  • 操作系统-存储管理

    为什么内存要分区?分区有哪些类型? 内存分区是为了方便地支持多程序运行。分区管理分为固定分区和可变分区,固定分区是...

  • NSXMLParser解析多分区

    { NSString *new; NSMutableDictionary *dic; NSMutableArray...

  • SPARK[RDD之partitions]

    RDD是容错、并行的数据结构,具备分区的属性,这个分区可以是单机上分区也可以是多机上的分区,对于RDD分区的数量涉...

  • Hive01

    Hive 启动 Hive 启动方式 建表语法【单分区】示例: 加载【单分区】数据示例: 【多分区】示例: 加载【多...

  • Ubuntu

    安装ubuntu时的分区 主机无法解析 修改hostssudo vim /etc/hosts127.0.1.1 z...

  • Kafka的分区数和消费者个数

    Kafka的分区数是不是越多越好? 分区多的优点 kafka使用分区将topic的消息打散到多个分区分布保存在不同...

  • (十四)GeoSpark源码解析(三)

    GeoSpark源码解析(三) 本节我们在来看一个SpatialRDD的成员indexedRawRDD 分区可以说...

  • 操作系统应用

    引导 多操作系统引导顺序 磁盘管理 磁盘分区主分区逻辑分区逻辑驱动器 磁盘整理 设备管理 查看设备驱动是否正常工作...

网友评论

      本文标题: GDataXMLElement解析多分区

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