|
//
// readHistoryTableController.m
// ThePaperBase
//
// Created by Huixin on 15/9/29.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "readHistoryTableController.h"
#import "readHistoryCell.h"
#import "Reachability.h"
#import "readHistoryViewModel.h"
@interface readHistoryTableController () <readHistoryViewModelDelegate>
@property(nonatomic, strong)readHistoryViewModel *viewModel;
@end
@implementation readHistoryTableController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor clearColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.clipsToBounds = YES;
[self configCanRefresh:NO canLoad:YES];
[self needNoFirstAutoRefresh];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
_viewModel = [readHistoryViewModel new];
_viewModel.delegate = self;
}
- (void)setDataList:(NSMutableArray *)list {
_dataList = list;
[self.tableView reloadData];
}
- (void)pullLoadMoreHander {
if (isBlankString(self.nextUrl)) {
[self loadFailed];
return;
}
// [Remote doJsonAction:2 requestUrl:self.nextUrl parameter:nil delegate:self];
[_viewModel getReadHistoryWithURL:self.nextUrl];
}
//#pragma mark - remote delegate
//-(void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData{
// if (actionTag == 2) {
// NSMutableArray *oldCollectList= [NSMutableArray arrayWithArray:self.dataList];
// NSMutableArray *newCollectList = [NSMutableArray array];
// NSArray *list = responsData[@"dataList"];
// [list enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) {
// listContObjectVO *listBo = setJsonDicToDataModel(obj, [listContObjectVO class]);
// [newCollectList addObject:listBo];
// }];
//
// [oldCollectList addObjectsFromArray:newCollectList];
// self.dataList = oldCollectList;
// [self loadSuccess];
//
// NSString *url = responsData[@"nextUrl"];
// self.nextUrl = url;
// }
//}
//
//- (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code {
// ShowTextMessage(message);
// [self loadFailed];
//}
#pragma mark - viewmodel delegate
- (void)returnReadHistoryList:(NSMutableArray*)data nextUrl:(NSString*)url {
NSMutableArray *list= [NSMutableArray arrayWithArray:self.dataList];
[list addObjectsFromArray:data];
self.dataList = list;
[self loadSuccess];
self.nextUrl = url;
}
- (void)returnErrorMessage:(NSString*)msg {
ShowTextMessage(msg);
[self loadFailed];
}
#pragma mark - uitableView
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _dataList.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (!_dataList || _dataList.count == 0) {
return 0;
}else {
return 80;
}
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *readHistoryCellId = @"readHistoryCell";
readHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:readHistoryCellId];
if (nil == cell) {
cell = [[readHistoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:readHistoryCellId];
}
listContObjectVO* listBO = _dataList[indexPath.row];
[cell setListBO:listBO];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([self.delegate respondsToSelector:@selector(readHistoryGoToContent:)]) {
listContObjectVO *data = _dataList[indexPath.row];
[self.delegate readHistoryGoToContent:data];
}
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (void) reachabilityChanged:(NSNotification *)notification {
[self.tableView reloadData];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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
|