//
// RootViewController.m
// MVC
//
//
//
// Created by on 15/8/5.
// Copyright (c) 2015
年
Congwang. All rights reserved.
//
#import "RootViewController.h"
#import "HomePageTableView.h"
#import "NetWorkingEngine.h"
#import "ContentModel.h"
@interface RootViewController ()<</span>UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)HomePageTableView *homePageViewTV;
@property (nonatomic, strong)NSMutableArray *dataSource;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
//初始化数组
self.dataSource = [NSMutableArray array];
self.homePageViewTV = [[HomePageTableView alloc]initWithFrame:[UIScreen mainScreen].boundsstyle:UITableViewStylePlain];
self.homePageViewTV.delegate = self;
self.homePageViewTV.dataSource = self;
//注册cell
[self.homePageViewTV registerClass:[UITableViewCell class]forCellReuseIdentifier:@"cell"];
//添加视图
[self.view addSubview:self.homePageViewTV];
[[NetWorkingEngine shardNetWorkingEngine]getInfoFromServerWithUrl Str:@"http://m2.qiushibaike.com/article/list/text?count=30&page=" withSuccess:^(NSData *response){
NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:response options:NSJSONReadingMutableCont ainers error:nil];
NSArray *itemsArray = dic[@"items"];
NSLog(@"%@",itemsArray);
for (NSDictionary *userDic in itemsArray) {
ContentModel *model = [[ContentModel alloc]initWithDic:userDic];
[self.dataSource addObject:model];
}//tableView刷新
//
#import "RootViewController.h"
#import "HomePageTableView.h"
#import "NetWorkingEngine.h"
#import "ContentModel.h"
@interface RootViewController ()<</span>UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)HomePageTableView *homePageViewTV;
@property (nonatomic, strong)NSMutableArray *dataSource;
@end
@implementation RootViewController
- (void)viewDidLoad {
}
#pragma mark -- UITableViewDataSource 的方法
- ( NSInteger )numberOfSectionsInTableV
}
- ( NSInteger )tableView:( UITableView *)tableView numberOfRowsInSection:( NSInteger )section{
}
- ( UITableViewCell *)tableView:( UITableView *)tableView cellForRowAtIndexPath:( NSIndexPath *)indexPath{
}
- ( void )didReceiveMemoryWarning {
}
@end
NetWorkingEngine.h
//
// NetWorkingEngine.h
// MVC
//
// Created by lanouhn on 15/8/5.
// Copyright (c) 2015年 Congwang. All rights reserved.
//
#import
@interface NetWorkingEngine : NSObject
+ (NetWorkingEngine *)shardNetWorkingEngine;
//请求数据的方法
//
//
//
//
//
//
#import
@interface NetWorkingEngine : NSObject
+ (NetWorkingEngine *)shardNetWorkingEngine;
//请求数据的方法
//block
做参数
:(void (^)(NSData *response))block
的类型
- (void)getInfoFromServerWithUrl Str:(NSString *)urlStr withSuccess:(void (^)(NSData *response))success withFailure:(void (^)(NSError *error))failure;
@end
NetWorkingEngine.m
//
// NetWorkingEngine.m
// MVC
//
//
//
// Created by on 15/8/5.
// Copyright (c) 2015年 Congwang. All rights reserved.
//
#import "NetWorkingEngine.h"
@implementation NetWorkingEngine
//单例方法的实现
+ (NetWorkingEngine *)shardNetWorkingEngine{
static NetWorkingEngine *netWorkEngine = nil;
//GCD - 单例写法
//在每个线程下都执行一次
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
netWorkEngine = [[NetWorkingEngine alloc] init];
});
return netWorkEngine;
}
//
#import "NetWorkingEngine.h"
@implementation NetWorkingEngine
//单例方法的实现
+ (NetWorkingEngine *)shardNetWorkingEngine{
}
//
请求数据的方法
-- 封装系统的请求数据的方法
- (void)getInfoFromServerWithUrl Str:(NSString *)urlStr withSuccess:(void (^)(NSData *))success withFailure:(void (^)(NSError *))failure{
}
@end
ContentModel.h
//
// ContentModel.h
// MVC
//
//
//
// Created by on 15/8/5.
// Copyright (c) 2015年 Congwang. All rights reserved.
//
#import
@interface ContentModel : NSObject
// 内容属性
@property (nonatomic, copy)NSString *contentStr;
- (id)initWithDic:(NSDictionary *)dic;
@end
//
#import
@interface ContentModel : NSObject
// 内容属性
@property (nonatomic, copy)NSString *contentStr;
- (id)initWithDic:(NSDictionary *)dic;
@end
ContentModel.m
//
// ContentModel.m
// MVC
//
//
//
// Created by on 15/8/5.
// Copyright (c) 2015年 Congwang. All rights reserved.
//
#import "ContentModel.h"
@implementation ContentModel
-(id)initWithDic:(NSDictionary *)dic{
if (self = [super init]) {
self.contentStr = dic[@"content"];
}return self;
}
@end
//
#import "ContentModel.h"
@implementation ContentModel
-(id)initWithDic:(NSDictionary *)dic{
@end