一个简单的解析

首先先导入MJExtension,SDWebImage,AFNetworking

创建UITableviewcell和Model, UITableviewcell记得点XIB

在viewcontrollerl里:

import "Model.h"

import "TableViewCell.h"

import "MJExtension.h"

import "AFNetworking.h"

import "UIImageView+WebCache.h"

@interface ViewController ()

@property(nonatomic,strong)UITableView *tab;
@property(nonatomic,strong)NSMutableArray *arr;

@end

@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];

    [self jiexi];

    [self.view addSubview:self.tab];

}

-(void)jiexi{

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@"http://test.bit.api.meeboo.cc/?method=app.news.getarticlelist&class_id=3&_debug=Y" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
    
    self.arr = [Model mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"list"]];
    
    [self.tab reloadData];
    
    NSLog(@"JSON: %@", responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

}

-(UITableView *)tab{

if (!_tab) {
    _tab = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tab.dataSource = self;
    _tab.delegate = self;
    
    _tab.rowHeight = 150;
    
    [self.tab registerNib:[UINib nibWithNibName:@"TableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
}

return _tab;

}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _arr.count;

}

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

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

Model *md = _arr[indexPath.row];

NSURL *url = [NSURL URLWithString:md.img];

[cell.img sd_setImageWithURL:url];

cell.lab1.text = md.title;
cell.lab2.text = md.author;
cell.lab3.text = md.create_time;




return cell;

}
Model里写
model.h里:
@property(nonatomic,strong)NSString title,author,create_time,img;

在UITableviewcell的Xib拖控件


一个简单的解析_第1张图片
屏幕快照 2019-01-20 上午10.36.53.png

model.h里
@property (weak, nonatomic) IBOutlet UIImageView *img;
@property (weak, nonatomic) IBOutlet UILabel *lab1;
@property (weak, nonatomic) IBOutlet UILabel *lab2;
@property (weak, nonatomic) IBOutlet UILabel *lab3;

你可能感兴趣的:(一个简单的解析)