// // moreTableViewController.m // ThePaperBase // // Created by zhousan on 15/7/23. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "moreTableViewController.h" #import "moreTableViewCell.h" #import "ImageSingleCell.h" @interface moreTableViewController () { NSMutableArray *contentList; NSMutableArray *heightArray; } @end @implementation moreTableViewController - (void)viewDidLoad { [super viewDidLoad]; self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self configCanRefresh:YES canLoad:YES]; [self manualRefresh]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } - (void)needrefreshNightMode:(id)sender{ self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } - (void)setNodeID:(NSString *)nodeID { if (_nodeID != nodeID) { _nodeID = nodeID; } } - (void)remoteAction { NSDictionary *dic = @{@"n":self.nodeID}; [Remote doJsonAction:1 requestUrl:nodeContentListURL parameter:dic delegate:self]; } - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if (actionTag == 1) { contentList = [NSMutableArray array]; heightArray = [NSMutableArray array]; int readmode = [[TPUserDefault instance].readModeStr intValue]; if (readmode == intelligentMode) { if ([Remote IsEnableWIFI]) { readmode = imageMode; }else { readmode = textMode; } } if (readmode == imageMode) { [contentList addObject:self.specialBo]; NSString *imageHeightStr = [NSString stringWithFormat:@"%f",85*rect_screen.size.width/320]; [heightArray addObject:imageHeightStr]; }else{ } nodeObjectBO *nodeBO = setJsonDicToDataModel(responsData, [nodeObjectBO class]); [nodeBO.contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { listContObjectVO *liveVO = setJsonDicToDataModel(obj, [listContObjectVO class]); [contentList addObject:liveVO]; CGFloat heigt = returnTextHeightWithRTLabel(liveVO.name, rect_screen.size.width-35, appFont(15, NO), 10); NSString *heightStr = [NSString stringWithFormat:@"%f",heigt + 45.f]; [heightArray addObject:heightStr]; }]; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; [self endRefresh]; [self.tableView reloadData]; }else { nodeObjectBO *nodeBO = setJsonDicToDataModel(responsData, [nodeObjectBO class]); [nodeBO.contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { listContObjectVO *liveVO = setJsonDicToDataModel(obj, [listContObjectVO class]); [contentList addObject:liveVO]; CGFloat heigt = returnTextHeightWithRTLabel(liveVO.name, rect_screen.size.width-35, appFont(15, NO), 10); NSString *heightStr = [NSString stringWithFormat:@"%f",heigt + 45.f]; [heightArray addObject:heightStr]; }]; [self endRefresh]; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; [self.tableView reloadData]; } } #pragma mark - TPTableView delegate - (void)pullRefreshHandler { NSDictionary *dic = @{@"n":self.nodeID}; [Remote doJsonAction:1 requestUrl:nodeContentListURL parameter:dic delegate:self]; } - (void)pullLoadMoreHander { [Remote doJsonAction:2 requestUrl:self.nextUrl parameter:nil delegate:self]; } #pragma mark - tableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return contentList.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if ([contentList[indexPath.row] isKindOfClass:[specialObjectBO class]]) { return [self getSpecialCellWithTableView:tableView cellForRowAtIndexPath:indexPath]; }else{ static NSString *cellId = @"moreCellId"; moreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { cell = [[moreTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; } listContObjectVO *listContOj = contentList[indexPath.row]; cell.timeString = listContOj.pubTime; cell.contentString = listContOj.name; return cell; } } - (ImageSingleCell *)getSpecialCellWithTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *specell = @"specellID"; ImageSingleCell *cell = [tableView dequeueReusableCellWithIdentifier:specell]; if (!cell) { cell = [[ImageSingleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:specell]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } cell.imageUrl = self.specialBo.pic; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [heightArray[indexPath.row] floatValue]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; if ([contentList[indexPath.row] isKindOfClass:[listContObjectVO class]]) { pushContentWithListContentObject(self.navigationController, contentList[indexPath.row]); } } - (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