AFNetting MJExtension.h 解析

1.coco 导入
pod ‘AFNetworking’
pod ‘MJExtension’
2.M中创建继承NSObject 文件为MD
在M.h中写属性

@property (nonatomic, copy) NSString * img;
@property (nonatomic, copy) NSString * Ztext;
@property (nonatomic, copy) NSString * Ftext;

3.在C中创建继承UIViewControl 的PY文件
在PY.m中

#import "PY.h"
#define Start_X          45.0f      // 第一个按钮的X坐标
#define Start_Y          50.0f     // 第一个按钮的Y坐标
#define Width_Space      5.0f      // 2个按钮之间的横间距
#define Height_Space     20.0f     // 竖间距
#define Button_Height   122.0f    // 高
#define Button_Width    75.0f    // 宽
#import "MD.h"
#import <MJExtension.h>

@interface PY ()<UITableViewDelegate,UITableViewDataSource>{
    UITableView *tab;
}
//@property(nonatomic,strong)NSArray *dataSouce;

@property (nonatomic, strong) NSMutableArray *mArr;
@end

@implementation PY

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"朋友" style:UIBarButtonItemStyleDone target:self action:@selector(zz)];
    
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"?   ?‍?   ➕" style:UIBarButtonItemStyleDone target:self action:@selector(yy)];
    
    self.navigationController.navigationBar.barTintColor=[UIColor blackColor];
    tab=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    tab.delegate=self;
    tab.dataSource=self;
    
    [self.view addSubview:tab];
}
-(void)yy{
    //创建路径
    NSURL *url=[NSURL URLWithString:@"http://127.0.0.1/Property%20List.json"];
    //读取文件
    NSData *data = [NSData dataWithContentsOfURL:url];
    
    
    //解析json数据   将json转换为oc对象  序列化
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    //一层一层的解析
    NSDictionary *plistDic = dict[@"plist"];
    NSDictionary *dictDic = plistDic[@"dict"];
    NSArray *studentArr = dictDic[@"student"];
    //初始化可变数组
    self.mArr = [NSMutableArray array];
    //for in 解析
    for (NSDictionary *dic in studentArr) {
        //将新的字典给model
        MD *model = [MD mj_objectWithKeyValues:dic];
        //将model给可变数组
        [self.mArr addObject:model];
    }
    //刷新
    [tab reloadData];
 
    

   
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
        return self.mArr.count;
    
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=[tab dequeueReusableCellWithIdentifier:@"11"];
    if(!cell){
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"11"];
        
    }
    
    //将数组所有内用给MD里面的属性
    MD *model = self.mArr[indexPath.row];
    //将MD图片位置 转换为data类型
    NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:model.img]];
    //将data类型加入
    cell.imageView.image = [UIImage imageWithData:imgData];
    cell.textLabel.text = model.Ztext;
    cell.detailTextLabel.text = model.Ftext;
    return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 130;
}
//页眉内容

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *vidw=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 130)];
    NSArray *img1=@[@"10.jpg",@"18.jpg",@"11.jpg"];
    NSArray *Stext=@[@"生活号",@"小程序",@"生活圈"];
    NSArray *Xtext=@[@"一个神奇的杯子",@"发现更多精品服务",@"和朋友分享生活"];
    for(int i=0;i<3;i++){
        UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(i * (Button_Width + 35.0f) + Start_X ,  20, 50, 50)];
        [button setImage:[UIImage imageNamed:img1[i]] forState:UIControlStateNormal];
        button.backgroundColor=[UIColor yellowColor];
        [vidw addSubview:button];
    }
    for(int i=0;i<3;i++){
        UILabel *la=[[UILabel alloc]initWithFrame:CGRectMake(i * (Button_Width + 30.0f) + Start_X ,  70, 100, 20)];
        la.text=Stext[i];
        [vidw addSubview:la];
    }
    for(int i=0;i<3;i++){
        UILabel *la=[[UILabel alloc]initWithFrame:CGRectMake(i * (Button_Width + 45.0f) + 10.0f ,  100, 200, 20)];
        la.text=Xtext[i];
        la.textColor=[UIColor lightGrayColor];
        la.font=[UIFont systemFontOfSize:13];
        [vidw addSubview:la];
        
    }
    return vidw;
}














@end

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值