ios json

作者: 三更夜半鬼仇天 | 来源:发表于2018-11-23 00:27 被阅读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

    • (void)viewDidLoad {

      [super viewDidLoad];

      // Do any additional setup after loading the view.

    [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;
    

    }

    • (void)segumentSelectionChange:(NSInteger)selection{

      if(selection ==0) {

        NSLog(@"新动态");
      
      
      
        self.tbv.hidden=NO;
      

      }else{

        NSLog(@"iOS教程");
      
        self.tbv.hidden=YES;
      

      }

    }

    -(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

    • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

      // Get the new view controller using [segue destinationViewController].

      // Pass the selected object to the new view controller.

    }

    */

    @end

    WoViewController.m

    ()<UITableViewDelegate,UITableViewDataSource>

    @property(nonatomic,strong)UITableView *tbv;

    @property(nonatomic,strong)UIImageView *headerV;

    @property(nonatomic,strong) UIImagePickerController *imagePicker;

    @end

    @implementationWoViewController

    • (void)viewDidLoad {

      [super viewDidLoad];

      // Do any additional setup after loading the view.

    [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的点击事件-

    • (void)headClick {

      //自定义消息框

      UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"拍照",@"从相册选择", nil];

      sheet.tag=2550;

      //显示消息框

      [sheetshowInView:self.view];

    }

    pragma mark -消息框代理实现-

    • (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

      if(actionSheet.tag==2550) {

        NSUIntegersourceType =0;
      
        // 判断系统是否支持相机
      
        _imagePicker = [[UIImagePickerController alloc] init];
      
      
      
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
      
            _imagePicker.delegate=self;//设置代理
      
            _imagePicker.allowsEditing=YES;
      
            _imagePicker.sourceType= sourceType;//图片来源
      
            if(buttonIndex ==0) {
      
                return;
      
            }elseif(buttonIndex ==1) {
      
                //拍照
      
                sourceType =UIImagePickerControllerSourceTypeCamera;
      
                _imagePicker.sourceType= sourceType;
      
                [self presentViewController:_imagePicker animated:YES completion:nil];
      
            }elseif(buttonIndex ==2){
      
                //相册
      
                sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
      
                _imagePicker.sourceType= sourceType;
      
                [self presentViewController:_imagePicker animated:YES completion:nil];
      
      
      
            }
      
        }else{
      
            if(buttonIndex ==0) {
      
                return;
      
            }
      
            sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
      
            _imagePicker.sourceType= sourceType;
      
            [self presentViewController:_imagePicker animated:YES completion:nil];
      
            //            return;
      
        }
      
      
      
      
      
        _headerV.layer.borderWidth = 1;
      
        _headerV.layer.borderColor = [UIColor lightGrayColor].CGColor;
      
        _headerV.userInteractionEnabled = YES;
      
        [_headerV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headClick)]];
      

      }

    }

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

    • (void)imagePickerController:(UIImagePickerController)picker didFinishPickingMediaWithInfo:(NSDictionary)info {

      [pickerdismissViewControllerAnimated:YES completion:^{}];

      UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; //通过key值获取到图片

      _headerV.image= image; //给UIimageView赋值已经选择的相片

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

    }

    /*

    pragma mark - Navigation

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

    • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

      // Get the new view controller using [segue destinationViewController].

      // Pass the selected object to the new view controller.

    }

    */

    @end

    相关文章

      网友评论

          本文标题:ios json

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