首先创建工程 在工程中导入 AFN MJE MF
在viewcontroller.m里
#import "ViewController.h"
#import "AFNetworking.h"
#import "MJExtension.h"
#import "Model.h"
#import "MJRefresh.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView *tbv;
@property(nonatomic,strong)NSMutableArray *datasource;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self jiexi];
[self.view addSubview:self.tbv];
[self loadbata];
}
-(void)loadbata{
self.tbv.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
// 马上进入刷新状态
[self.tbv.mj_header beginRefreshing];
}
-(void)loadNewData{
}
-(void)jiexi{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:@"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.datasource =[Model mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"list"]];
[self.tbv reloadData];
[self.tbv.header endRefreshing];
NSLog(@"JSON: %@", responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
-(UITableView *)tbv{
if (!_tbv)
{
_tbv=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
}
_tbv.delegate=self;
_tbv.dataSource=self;
return _tbv;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _datasource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString*str=@"str";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
if (!cell)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];
}
Model *md=_datasource[indexPath.row];
cell.textLabel.text=md.title;
cell.detailTextLabel.text=md.author;
return cell;
}
@end
model里写
@property(nonatomic,strong)NSString *title,*author,*create_time;