本地解析

导入框架

pod ‘AFNetworking’
pod 'SVProgressHUD

#import “fourViewController.h”
#import “fiveViewController.h”
#import <SVProgressHUD.h>
#import <AFNetworking.h>
#import “Model.h”
@interface fourViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *table;
@property(nonatomic,strong)NSMutableArray *dataArr;
@end

@implementation fourViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@“朋友” style:UIBarButtonItemStylePlain target:self action:@selector(click)];
    self.dataArr=[[NSMutableArray alloc]init]; self.navigationController.navigationBar.barTintColor=[UIColor blueColor];//导航背景色

    [self loadData];
    [self headview];
    [self.view addSubview:self.table];

}

-(UITableView *)table{
    if(!_table){
        
        _table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        _table.delegate = self;
        _table.dataSource = self;
        
    }
    
    return _table;
    
}

-(void)headview
{
    UIView *view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen ].bounds.size.width, 180)];
    UIImageView *imageI=[[UIImageView alloc]initWithFrame:CGRectMake(0, 30, [UIScreen mainScreen ].bounds.size.width, 150)];
    imageI.image=[UIImage imageNamed:@"Image"];
    [view1 addSubview:imageI];
    
    self.table.tableHeaderView=view1;
    
}

-(void)loadData{
    //显示加载栏
    //    [SVProgressHUD showWithStatus:@"加载中"];
    
    
    //GET 请求
    //创建网络路径
    NSURL *url = [NSURL URLWithString: @"http://127.0.0.1/PengYou.json"];
    //创建网络请求
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    //获取会话对象
    NSURLSession *session = [NSURLSession sharedSession];
    //根据会话对象  创建一个task任务
    NSURLSessionDataTask *sessionTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        //对服务器返回的数据进行处理
        if (!error) {
            NSLog(@"data :%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
            
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:1 error:nil];
            NSArray *arr = dic[@"result"];
            for (NSDictionary *di in arr) {
                Model *model = [[Model alloc] init];
                [model setValuesForKeysWithDictionary:di];
                [self.dataArr addObject:model];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.table reloadData];
                    [SVProgressHUD dismiss];
                });
            }
        }else{
            NSLog(@"请求失败 error :%@",error);
        }
    }];
    //执行任务
    [sessionTask resume];
    
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

NSArray *arrI2=@[@"Image-5",@"Image-1",@"Image-2",@"Image-3",@"Image-4",@"Image-5"];
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
    cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}

 Model *model = self.dataArr[indexPath.row];

cell.imageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.imageV]]];
cell.textLabel.text=[NSString stringWithFormat:@"%@",model.TeLabel];
cell.detailTextLabel.text=[NSString stringWithFormat:@"%@",model.DeLabel];

return cell;

}
-(void)click
{

//跳转到第二个控制器
fiveViewController *secVc = [fiveViewController new];

[self.navigationController pushViewController:secVc animated:YES];
[self headview];

}
@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值