解析

#import “AFNetworking/AFNetworking.h”
#define TEST_URL @“http://192.168.0.113/25yk.json

@interface OneViewController ()<UITableViewDelegate,UITableViewDataSource>
{

NSDictionary *_dic;
UITableView *tab;

}
@end

@implementation OneViewController

-(void)viewDidLoad {

[super viewDidLoad];
tab = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
tab.delegate = self;
tab.dataSource = self;
[self.view addSubview:tab];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [[AFJSONResponseSerializer alloc]init];
NSURL *url = [NSURL URLWithString:TEST_URL];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSURLSessionDataTask *task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
    
    self->_dic = responseObject;
    [self->tab reloadData];
}];
[task resume];

}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return _dic.count;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

NSString *str = [_dic.allKeys objectAtIndex:section];
return [[_dic objectForKey:str]count];

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

static NSString *strc = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strc];
if (!cell) {
    
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:strc];
}
NSString *str = [_dic.allKeys objectAtIndex:indexPath.section];
NSString *imgstr = [[[_dic objectForKey:str]objectAtIndex:indexPath.row]objectForKey:@"img"];
NSURL *urlimg = [NSURL URLWithString:imgstr];
NSData *data = [NSData dataWithContentsOfURL:urlimg];
cell.imageView.image = [[UIImage alloc]initWithData:data];
cell.textLabel.text = [[[_dic objectForKey:str]objectAtIndex:indexPath.row]objectForKey:@"name"];
cell.detailTextLabel.text = [[[_dic objectForKey:str]objectAtIndex:indexPath.row]objectForKey:@"like"];

return cell;

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

return [_dic.allKeys objectAtIndex:section];

}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

MyViewController *my = [[MyViewController alloc]init];

//获取某个分区
NSString *key = [_dic.allKeys objectAtIndex:indexPath.section];
//属性传值 字典
my.dic = [[_dic objectForKey:key]objectAtIndex:indexPath.row
          ];

[self presentViewController:my animated:YES completion:nil];

}

-(void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.

}

@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值