ios json

2018-11-23  本文已影响0人  三更夜半鬼仇天
![屏幕快照 2018-11-23 上午12.24.08.png](https://img.haomeiwen.com/i12846742/775057a4f60ee9c1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

-(void)setModel:(Model*)model{

_model= model;

self.titleLab.text= model.title;

self.imgV1.image= [UIImageimageNamed:model.img1];

self.imgV2.image= [UIImageimageNamed:model.img2];

self.text1.text= model.text1;

self.text2.text= model.text2;

}

BaogViewController.m

import "BaogViewController.h"

import "BaogTableViewCell.h"

import "AFNetworking/AFNetworking/AFHTTPSessionManager.h"

import "YJSegmentedControl/YJSegmentedControl.h"

import "Model.h"

import "MJExtension/MJExtension.h"

@interface BaogViewController ()<UITableViewDelegate,UITableViewDataSource,YJSegmentedControlDelegate>

@property(nonatomic,strong)UITableView *tbv;

@property(nonatomic,strong)NSArray *arr;

@end

@implementationBaogViewController

[self loadData];

[self createTbv];



NSArray* btnDataSource =@[@"攻略",@"训练营",@"咨询"];



YJSegmentedControl * segment = [YJSegmentedControl segmentedControlFrame:CGRectMake(0, 44, self.view.bounds.size.width, 44) titleDataSource:btnDataSource backgroundColor:[UIColor whiteColor] titleColor:[UIColor blueColor] titleFont:[UIFont fontWithName:@".Helvetica Neue Interface" size:16.0f] selectColor:[UIColor orangeColor] buttonDownColor:[UIColor blueColor] Delegate:self];



self.navigationItem.titleView = segment;

}

-(void)createTbv{

_tbv = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];



_tbv.dataSource = self;

_tbv.delegate=self;

[self.tbv registerNib:[UINib nibWithNibName:@"BaogTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"id"];



[self.viewaddSubview:self.tbv];



self.tbv.rowHeight=170;

}

}

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

return_arr.count;

}

-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section{

return 150;

}

-(UIView)tableView:(UITableView)tableView viewForHeaderInSection:(NSInteger)section{

UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];



imgV.image= [UIImageimageNamed:@"1"];



returnimgV;

}

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

BaogTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"id" forIndexPath:indexPath];

if(!cell) {

    cell = [[BaogTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"id"];

}



cell.model= [self.arrobjectAtIndex:indexPath.row];



returncell;

}

-(void)loadData{

AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];

NSString *url = @"http://127.0.0.1/BingqiuJson.json";

[mangerGET:urlparameters:nilprogress:nilsuccess:^(NSURLSessionDataTask*_Nonnulltask,id  _NullableresponseObject) {



    self.arr= responseObject[@"data"];



    self.arr= [Modelmj_objectArrayWithKeyValuesArray:responseObject[@"data"]];



    NSLog(@"%@",responseObject);

    NSLog(@"-------------%@",self.arr);

    [self.tbvreloadData];

}failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {

}];

}

/*

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

}

*/

@end

WoViewController.m

()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tbv;

@property(nonatomic,strong)UIImageView *headerV;

@property(nonatomic,strong) UIImagePickerController *imagePicker;

@end

@implementationWoViewController

[self createTbv];



self.title=@"学员资料";



self.navigationItem.rightBarButtonItem= [[UIBarButtonItemalloc]initWithTitle:@"切换学院"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(qiehuan)];

}

-(void)qiehuan{

}

-(void)createTbv{

_tbv = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];



_tbv.dataSource = self;

_tbv.delegate=self;



[self.viewaddSubview:self.tbv];

}

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

return 7;

}

-(CGFloat)tableView:(UITableView)tableView heightForRowAtIndexPath:(NSIndexPath)indexPath{

if(indexPath.row==0) {

    return100;

}

return 50;

}

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

if(!cell) {

    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];

}



NSArray *arr1 = @[@"更换头像",@"姓名",@"性别",@"生日",@"身高",@"体重",@"基础心率"];

NSArray *arr2 = @[@"",@"张小红",@"女",@"1994",@"150",@"300",@"70"];

if(indexPath.row==0) {

    cell.textLabel.text=@"更换头像";

    _headerV  = [[UIImageViewalloc]initWithFrame:CGRectMake(self.view.frame.size.width-100,10,80,80)];

    [_headerV setBackgroundColor:[UIColor yellowColor]];

    _headerV.layer.masksToBounds = YES;

    _headerV.layer.cornerRadius = 40;

    [celladdSubview:_headerV];

}else{

    cell.textLabel.text= arr1[indexPath.row];

    cell.detailTextLabel.text= arr2[indexPath.row];

}



returncell;

}

pragma mark -头像UIImageview的点击事件-

}

pragma mark -消息框代理实现-

}

pragma mark -实现图片选择器代理-(上传图片的网络请求也是在这个方法里面进行,这里我不再介绍具体怎么上传图片)

//上传图片到服务器--在这里进行图片上传的网络请求,这里不再介绍

//......

}

/*

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

}

*/

@end

上一篇 下一篇

猜你喜欢

热点阅读