#import "ViewController.h"
#import "Model.h"
#import "AFNetworking.h"
#import "MJExtension.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSArray *arr;
@property(nonatomic,strong)UITableView *tbv;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self createNav];
[self.view addSubview:self.tbv];
}
-(void)createNav{
//2.发送GET请求
/*
第一个参数:请求路径(不包含参数).NSString
第二个参数:字典(发送给服务器的数据~参数)
第三个参数:progress 进度回调
第四个参数:success 成功回调
task:请求任务
responseObject:响应体信息(JSON--->OC对象)
第五个参数:failure 失败回调
error:错误信息
响应头:task.response
*/
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//参数
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"method"] = @"app.news.getarticlelist";
params[@"class_id"] = @"3";
params[@"_debug"] = @"Y";
[manager POST:@"http://test.bit.api.meeboo.cc" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
[DataModel mj_setupObjectClassInArray:^NSDictionary *{
return @{
@"list":@"ImgModel"
};
}];
Model *model = [Model mj_objectWithKeyValues:responseObject];
self.arr = model.data.list;
[self.tbv reloadData];
NSLog(@"%@---%@",[responseObject class],responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"请求失败--%@",error);
}];
}
-(UITableView *)tbv{
if (!_tbv) {
_tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
}
_tbv.dataSource = self;
_tbv.delegate = self;
return _tbv;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
}
// cell.textLabel.text = [self.arr[indexPath.row] objectForKey:@"title"];
ImgModel *model = self.arr[indexPath.row];
cell.detailTextLabel.text = model.title;
return cell;
}
@interfaceImgModel :NSObject
@property(nonatomic,strong)NSDate *create_time;
@property(nonatomic,copy)NSString *id;
@property(nonatomic,copy)NSString *title;
@end
@interfaceDataModel :NSObject
@property(nonatomic,assign) int page;
@property(nonatomic,assign) int pages;
@property(nonatomic,copy) NSArray *list;
@end
@interface Model : NSObject
@property(nonatomic,assign) int code;
@property(nonatomic,strong) DataModel *data;
@end
@implementation ImgModel
@end
@implementation DataModel
@end
@implementation Model