|
//
// channelDetailListController.m
// ThePaperHD
//
// Created by scar1900 on 15/1/6.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "channelDetailListController.h"
#import "paperCollectCell.h"
#import "columnListController.h"
#import "detailContentHomeController.h"
#import "hotAnswerCell.h"
#import "topicListCell.h"
#import "topicHomeController.h"
#import "hotAskListHomeController.h"
#import "customFlowLayout.h"
#import "ImageContentController.h"
#import "TPcontentWebController.h"
#import "TPLiveHomeController.h"
#import "hotAnswerDetailController.h"
#import "otherPersonHomepageController.h"
#import "topicContentController.h"
#import "topicListTopView.h"
#import "topicListController.h"
#import "topicListHomeController.h"
#import "topicMoreInfoController.h"
#define PADDING 35
@interface channelDetailListController ()<paperCollectDelegate,UIGestureRecognizerDelegate,hotAnswerCellDelegate,hotAskListHomeDelegate,hotAnswerDetailDelegate> {
NSInteger remoteCount;
NSMutableArray *tempLoadList;
UIInterfaceOrientation lastOrientation;
}
@property(nonatomic,strong)NSMutableArray *dataList;
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)hotAskListHomeController *hotAskVC;
@property(nonatomic, strong)topicListHomeController *listHomeVC;
@end
@implementation channelDetailListController
@synthesize infoDic = _infoDic;
@synthesize dataList = _dataList;
@synthesize index;
static NSString * const channelDetailCollectItemIdentifer = @"channelDetailCollectItemIdentifer";
static NSString * const channelDetailHotAnswerItemIdentifer = @"channelDetailHotAnswerItemIdentifer";
static NSString * const channelDetailTopicItemIdentifer = @"channelDetailTopicItemIdentifer";
- (void)viewDidLoad {
[super viewDidLoad];
[self setLayoutBaseWithOrientation];
if (isIOS7) {
self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:[TPUserDefault instance].channldataList[index][@"color"]];
}else {
self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:[TPUserDefault instance].channldataList[index][@"color"]];
}
[self.collectionView registerClass:[paperCollectCell class] forCellWithReuseIdentifier:channelDetailCollectItemIdentifer];
// [self.collectionView registerClass:[hotAnswerCell class] forCellWithReuseIdentifier:channelDetailHotAnswerItemIdentifer];
[self.collectionView registerClass:[topicListCell class] forCellWithReuseIdentifier:channelDetailTopicItemIdentifer];
self.collectionView.alwaysBounceVertical = YES;
[self configCanRefresh:YES canLoad:YES];
self.collectionView.refreshControl.frame = CGRectMake(0,
self.collectionView.refreshControl.frame.origin.y+64,
CGRectGetWidth(self.collectionView.frame),
self.collectionView.refreshControl.frame.size.height);
[self manualRefresh];
tempLoadList = [NSMutableArray array];
remoteCount = 0;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshFrontPage) name:NEEDREFRESHENTERFORGROUND object:nil];
// if([self.infoDic[@"nodeId"] intValue] == -3){
//// [self.view addSubview:[topicListTopView new]];
//// [self.view addSubview:[topi]]
// self.listHomeVC = [topicListHomeController new];
// self.collectionView = self.listHomeVC.collectionView;
// }else{
//
// }
// if ([self.infoDic[@"nodeId"] intValue] == 25949) {
// [self enablePopBackGesture];
// }else [self disablePopBackGesture];
}
- (void)setRefreshControlInsectY:(CGFloat)insectY {
self.collectionView.refreshControl.originalContentInsectY = insectY;
}
- (UIView*)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:self.view.bounds];
}
return _backView;
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
}
- (void)viewWillAppear:(BOOL)animated {
//【倒退】问吧精选页:问吧精选页左滑一点或右滑一点回来之后问吧页上方颜色异常(bug:6040)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.06 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (isIOS7) {
self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:[TPUserDefault instance].channldataList[index][@"color"]];
}else {
self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:[TPUserDefault instance].channldataList[index][@"color"]];
}
//在精选界面手指稍微向左滑一点等右上角的“我的话题”字样出现后,迅速向右滑至首页,则再返回精选页面右上角会出现“我的话题”字样,出现后一直存在(bug:4910)
for (int i = 0; i < self.navigationController.navigationBar.subviews.count; i++) {
if ([self.navigationController.navigationBar.subviews[i] isKindOfClass:[UILabel class]]) {
[self.navigationController.navigationBar.subviews[i] removeFromSuperview];
}
}
});
if (isIOS7) {
self.automaticallyAdjustsScrollViewInsets = NO;
}
self.navigationController.navigationBar.translucent = YES;
[self pagesDidChange];
__weak typeof(self) Self = self;
if (self.hotAskVC && self.hotAskVC.isNeedHold) {
[self presentController:self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{
} dismiss:^{
if (!Self.hotAskVC.isNeedHold) {
Self.hotAskVC = nil;
}
}];
}
[super viewWillAppear:animated];
}
#pragma mark - navigation bar tap
- (void)naviBarTapHandler:(UITapGestureRecognizer*)tap {
[self.collectionView setContentOffset:CGPointZero animated:YES];
}
- (void)refreshRemoteMethod {
remoteCount = remoteCount + 1;
if ([self.infoDic[@"nodeId"] isEqualToString:@"-3"]) {//【需求】热追问加上话题(bug:3928)
NSDictionary *dic = @{@"n":self.infoDic[@"nodeId"]};
[Remote doJsonAction:1
requestUrl:channelNodeListURL
parameter:dic
delegate:self];
}else {
NSDictionary *dic = @{@"n":self.infoDic[@"nodeId"]};
[Remote doJsonAction:1
requestUrl:channelNodeListURL
parameter:dic
delegate:self];
}
}
-(void)hotAskHomeToTopic:(TopicInfoBO *)topic user:(userBO *)user{
__weak typeof(self) Self = self;
[self.hotAskVC dismissControllerAnimated:YES completion:^{
if (!Self.hotAskVC.isNeedHold) {
Self.hotAskVC = nil;
}
topicContentController *topicControllerVC = [[topicContentController alloc]init];
if (topic) {
topicControllerVC.preTopicInfo = topic;
topicControllerVC.creatUser = user;
}
[Self.navigationController pushViewController:topicControllerVC animated:YES];
}];
}
- (void)pagesDidChange {
// UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
// if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// if (self.view.bounds.size.width > self.view.bounds.size.height) {
// self.view.frame =CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width);
// }
// }else {
// if (self.view.bounds.size.width < self.view.bounds.size.height) {
// self.view.frame =CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width);
// }
// }
self.collectionView.frame = self.view.bounds;
[self setLayoutBaseWithOrientation];
self.collectionView.refreshControl.frame = CGRectMake(0,
self.collectionView.refreshControl.frame.origin.y,
CGRectGetWidth(self.collectionView.frame),
self.collectionView.refreshControl.frame.size.height);
}
- (customFlowLayout*)HorizontalLayout {
CGFloat width = (1024-PADDING*4)/3;
CGFloat viewScale = width/300;
CGSize itemSize = CGSizeMake(width, 215*viewScale);
customFlowLayout *layout= [[customFlowLayout alloc]init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.minimumLineSpacing = PADDING;
layout.minimumInteritemSpacing = PADDING;
layout.itemSize = itemSize;
return layout;
}
- (customFlowLayout*)VericalLayout {
CGFloat width = (768-PADDING*3)/2;
CGFloat viewScale = width/300;
CGSize itemSize = CGSizeMake(width, 215*viewScale);
customFlowLayout *layout= [[customFlowLayout alloc]init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.minimumLineSpacing = PADDING;
layout.minimumInteritemSpacing = PADDING;
layout.itemSize = itemSize;
return layout;
}
- (UIEdgeInsets)HorizontalInsets {
UIEdgeInsets top = {PADDING,PADDING,PADDING,PADDING};
return top;
}
- (UIEdgeInsets)VercalInsets {
UIEdgeInsets top = {PADDING,PADDING,PADDING,PADDING};
return top;
}
- (void)setLayoutBaseWithOrientation {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (lastOrientation != orientation && lastOrientation != UIInterfaceOrientationUnknown) {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
self.collectionLayout = [self VericalLayout];
}else {
self.collectionLayout = [self HorizontalLayout];
};
}
lastOrientation = orientation;
}
- (void)setInfoDic:(NSDictionary *)dic {
_infoDic = dic;
}
- (void)setDataList:(NSMutableArray *)list {
// if (_dataList.count > 0) {
// if ([self isListSame:list]) {
// return;
// }
// }
_dataList = list;
CGFloat insetY = 64;
if (isNotIOS7) {
insetY = 44;
}
[self setRefreshControlInsectY:insetY];
self.collectionView.refreshControl.frame = CGRectMake(0,
-110,
CGRectGetWidth(self.collectionView.frame),
self.collectionView.refreshControl.frame.size.height);
[self.collectionView reloadData];
if (remoteCount == 2) {
[self loadMoreMethod];
}
}
- (BOOL) isListSame:(NSArray*)list {
__block BOOL isSame = YES;
[list enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
id objOri = _dataList[idx];
NSDictionary *dic1 = setDataModelToDic(obj, [listContObjectVO class]);
NSDictionary *dic2 = setDataModelToDic(objOri, [listContObjectVO class]);
[dic1.allKeys enumerateObjectsUsingBlock:^(NSString* key, NSUInteger index, BOOL *stoped) {
id objCon = dic1[key];
if ([objCon isKindOfClass:[NSString class]]) {
NSString *str1 = objCon;
NSString *str2 = dic2[key];
if (![str1 isEqualToString:str2]) {
isSame = NO;
}
}
}];
}];
return isSame;
}
#pragma mark - refresh and load method
- (void)pullRefreshHandler{
[self refreshRemoteMethod];
}
- (void)pullLoadMoreHander {
[self loadMoreMethod];
}
- (void)loadMoreMethod {
if (isBlankString(self.nextUrl)) {
return;
}
[Remote doJsonAction:2
requestUrl:self.nextUrl
parameter:nil
delegate:self];
}
#pragma mark - needRefreshEnterForground
- (void)refreshFrontPage {
TPLOG(@"time to refresh ChannelList");
[self manualRefresh];
}
#pragma mark - collection delegate and datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (self.dataList) {
return self.dataList.count;
}else return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
id data = self.dataList[indexPath.row];
if ([data isKindOfClass:[listContObjectVO class]]){
return [self getCollectCell:collectionView cellForItemAtIndexPath:indexPath];
}else {
// return [self getHotAnswerCell:collectionView cellForItemAtIndexPath:indexPath];
return [self getTopicListCell:collectionView cellForItemAtIndexPath:indexPath];
}
}
- (paperCollectCell *)getCollectCell:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
paperCollectCell *cell = (paperCollectCell*)[collectionView dequeueReusableCellWithReuseIdentifier:channelDetailCollectItemIdentifer forIndexPath:indexPath];
listContObjectVO* data = self.dataList[indexPath.row];
if ([self isKindOfClass:[topicMoreInfoController class]]) {//bug fixed:(4585)专题页,导读显示不全,进入一个查看更多头两个卡片也显示专题
if ([data.cornerLabelDesc isEqualToString:@"专题"]) {
data.cornerLabelDesc = @"";
}
}
cell.listContentBO = data;
cell.delegate = self;
return cell;
}
- (hotAnswerCell*)getHotAnswerCell:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
hotAnswerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:channelDetailHotAnswerItemIdentifer forIndexPath:indexPath];
id data = self.dataList[indexPath.row];
cell.commentBO = data;
cell.delegate = self;
return cell;
}
-(topicListCell*) getTopicListCell:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath{
topicListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:channelDetailTopicItemIdentifer forIndexPath:indexPath];
id data = self.dataList[indexPath.row];
cell.topicBO = data;
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGFloat width = 0;
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
width = (768-35*3)/2;
CGFloat viewScale = width/300;
return CGSizeMake(width, 215*viewScale);
}else {
width = (1024-35*4)/3;
CGFloat viewScale = width/300;
return CGSizeMake(width, 215*viewScale);
}
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
return [self VercalInsets];
}else {
return [self HorizontalInsets];
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
id data = self.dataList[indexPath.row];
paperCollectCell *cell = (paperCollectCell*)[collectionView cellForItemAtIndexPath:indexPath];
if (ISNotRETINA) {
if ([data isKindOfClass:[listContObjectVO class]]) {
listContObjectVO *listItem = data;
pushContentWithListContentObject(self.navigationController, listItem);
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}else if ([data isKindOfClass:[commentObjectVO class]]) {
commentObjectVO *commentBO = data;
if (!self.hotAskVC) {
self.hotAskVC = [[hotAskListHomeController alloc]init];
self.hotAskVC.commentBO = commentBO;
if ([commentBO.objectType isEqualToString:@"3"]) {
self.hotAskVC.commentOT = @"3";
}
self.hotAskVC.delegate = self;
}
__weak typeof(self) Self = self;
[self presentController:Self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
} dismiss:^{
if (!Self.hotAskVC.isNeedHold) {
Self.hotAskVC = nil;
}
} tapHandler:^{
if (Self.hotAskVC.writeVC) {
[Self.hotAskVC.writeVC closeKeyBoard];
}
}];
}
}else {
[UIView animateWithDuration:0.25 animations:^{
cell.transform = CGAffineTransformMakeScale(0.95, 0.95);
} completion:^(BOOL finished) {
cell.transform = CGAffineTransformMakeScale(1.00, 1.00);
if ([data isKindOfClass:[listContObjectVO class]]) {
listContObjectVO *listItem = data;
pushContentWithListContentObject(self.navigationController, listItem);
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}else if ([data isKindOfClass:[commentObjectVO class]]) {
commentObjectVO *commentBO = data;
if (!self.hotAskVC) {
self.hotAskVC = [[hotAskListHomeController alloc]init];
self.hotAskVC.commentBO = commentBO;
if ([commentBO.objectType isEqualToString:@"3"]) {
self.hotAskVC.commentOT = @"3";
}
self.hotAskVC.delegate = self;
}
__weak typeof(self) Self = self;
[self presentController:Self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
} dismiss:^{
if (!Self.hotAskVC.isNeedHold) {
Self.hotAskVC = nil;
}
} tapHandler:^{
if (Self.hotAskVC.writeVC) {
[Self.hotAskVC.writeVC closeKeyBoard];
}
}];
}
}];
}
}
-(void)gotoPersonInfo:(commentObjectVO *)comment{
self.hotAskVC.isNeedHold = YES;
[self dismissControllerAnimated:YES completion:^{
otherPersonHomepageController *otherVC = [otherPersonHomepageController new];
otherVC.commentBo = comment;
[self.navigationController pushViewController:otherVC animated:YES];
}];
}
- (void)goToColumnPage:(listContObjectVO *)listBO {
customFlowLayout *layout = nil;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
layout = [self VericalLayout];
}else {
layout = [self HorizontalLayout];
}
columnListController *vc = [[columnListController alloc]initWithCollectionViewLayout:layout];
vc.listBO = listBO;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)titleClick:(commentObjectVO *)contBO {
commentObjectVO *commentBO = contBO;
if([commentBO.objectType integerValue] !=3){
pushContentWithCommentBO(self.navigationController, commentBO);
}else{
TopicInfoBO *topic = [[TopicInfoBO alloc] init];
topic.topicId = commentBO.contId;
NSMutableDictionary *topicHost = commentBO.answerList[0];
userBO *user = setJsonDicToDataModel(topicHost[@"userInfo"], [userBO class]);
// __weak typeof(self) Self = self;
topicContentController *topicControllerVC = [[topicContentController alloc]init];
if (topic) {
topicControllerVC.preTopicInfo = topic;
topicControllerVC.creatUser = user;
}
[self.navigationController pushViewController:topicControllerVC animated:YES];
}
}
- (void)popDetailAnswerPage:(commentObjectVO *)comment backColor:(UIColor *)color{
CGFloat contentNameHeight = heightForString(comment.contName, appFont(11, NO), 850/2, NSLineBreakByWordWrapping);
CGFloat askHeight = heightForString(comment.content, appFont(20, YES), 850/2, NSLineBreakByWordWrapping);
NSDictionary *answerDic = comment.answerList[0];
commentObjectVO *answerBO = setJsonDicToDataModel(answerDic, [commentObjectVO class]);
CGFloat answerHeight = heightForString(answerBO.content, appFont(14, NO), 350, NSLineBreakByWordWrapping)+35;
if (answerHeight<50) {
answerHeight = 50;
}
if (answerHeight>320) {
answerHeight = 320;
}
hotAnswerDetailController *hotAnswerVC = hotAnswerDetailController.new;
hotAnswerVC.contentNameHeight = contentNameHeight;
hotAnswerVC.askHeight = askHeight;
hotAnswerVC.answerHeight = answerHeight;
hotAnswerVC.commentBO = comment;
hotAnswerVC.delegate = self;
hotAnswerVC.backColor = color;
CGSize size = CGSizeMake(966/2,110+16+contentNameHeight+15+askHeight+25+answerHeight+15);
[self presentController:hotAnswerVC animated:YES presentSize:size completion:^{
}];
}
#pragma mark - hot ask list delegate
- (void)goToOriginContent:(objInfoBO *)commentBO presentedController:(TPHttpController *)presentedController{
__weak typeof(self) Self = self;
[presentedController dismissControllerAnimated:YES completion:^{
pushContentWithObjInfo(Self.navigationController, commentBO);
}];
}
#pragma mark - answer detail delegate
- (void)answerDetailGoToOriginContent:(commentObjectVO *)commentBO presentedController:(TPHttpController *)presentedController {
__weak typeof(self) Self = self;
[presentedController dismissControllerAnimated:YES completion:^{
pushContentWithCommentBO(Self.navigationController, commentBO);
}];
}
- (void)goToAskDetail:(commentObjectVO *)comment presentedController:(TPHttpController *)presentedController {
__weak typeof(self) Self = self;
[presentedController dismissControllerAnimated:YES completion:^{
// 热追问中先点回答,再点问题,然后点“进入原话题”,没有跳转(bug:4263)
if(Self.hotAskVC){
Self.hotAskVC = nil;
}
Self.hotAskVC = [[hotAskListHomeController alloc]init];
Self.hotAskVC.commentBO = comment;
Self.hotAskVC.delegate = Self;
[Self presentController:Self.hotAskVC animated:YES presentSize:hotAskListPopUpSize completion:^{
}dismiss:^{
}tapHandler:^{
if (Self.hotAskVC.writeVC) {
[Self.hotAskVC.writeVC closeKeyBoard];
}
}];
}];
}
#pragma mark - remote delegate
- (void)configNodeInfoWithResData:(id)resData {
}
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData {
if (actionTag == 1) {
[self configNodeInfoWithResData:responsData];
remoteCount = 2;
if (![self.infoDic[@"nodeId"] isEqualToString:@"-3"]) {
[self getRefreshDataFromDic:responsData sourceKey:@"contList" contentClass:[listContObjectVO class]];
}else {
[self getRefreshDataFromDic:responsData sourceKey:@"topicList" contentClass:[TopicInfoBO class]];
}
// tempLoadList = [NSMutableArray array];
}else {
NSArray *contList = [NSArray array];
if (![self.infoDic[@"nodeId"] isEqualToString:@"-3"]) {
contList = responsData[@"contList"];
}else {
contList = responsData[@"topicList"];
}
if (contList && contList.count > 0) {
// if (remoteCount == 0) {
//// [self.dataList addObjectsFromArray:tempLoadList];
// }
@try
{
[self.collectionView performBatchUpdates:^{
NSMutableArray *oriListData = [NSMutableArray arrayWithArray:self.dataList];
NSMutableArray *tempArray = [NSMutableArray array];
[contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (![self.infoDic[@"nodeId"] isEqualToString:@"-3"]) {
listContObjectVO *contentBO = setJsonDicToDataModel(obj, [listContObjectVO class]);
if (!contentBO.title) {
[tempArray addObject:contentBO];
}
}else {
// commentObjectVO *contentBO = setJsonDicToDataModel(obj, [commentObjectVO class]);
TopicInfoBO *topicBo = setJsonDicToDataModel(obj, [TopicInfoBO class]);
[tempArray addObject:topicBo];
}
}];
[self.dataList addObjectsFromArray:tempArray];
NSMutableArray *indexList = [NSMutableArray array];
for (NSInteger i=oriListData.count;i<self.dataList.count;i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
[indexList addObject:indexPath];
}
// tempLoadList = [NSMutableArray array];
NSString *url = responsData[@"nextUrl"];
self.nextUrl = url;
remoteCount = 0;
[self.collectionView insertItemsAtIndexPaths:indexList];
} completion:^(BOOL finished) {
}];
}
@catch (NSException *except)
{
NSLog(@"DEBUG: failure to insertItemsAtIndexPaths. %@", except.description);
}
}else {
TPLOG(@"加载数据为空");
[self loadSuccess];
}
}
}
- (void)getRefreshDataFromDic:(NSDictionary*)sourceDic sourceKey:(NSString*)sourceKey contentClass:(Class)contentClass{
NSArray *contList = sourceDic[sourceKey];
if (contList && contList.count > 0) {
NSMutableArray *tempArray = [NSMutableArray array];
[contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
id contentBO = setJsonDicToDataModel(obj, contentClass);
if ([contentBO isKindOfClass:[listContObjectVO class]]) {
listContObjectVO *listContentBO = contentBO;
if (!listContentBO.title && [listContentBO.cardMode intValue] != 1
&& ([listContentBO.cardMode intValue] == 2 || [listContentBO.cardMode intValue] == 3)) {
[tempArray addObject:contentBO];
}
}else {
[tempArray addObject:contentBO];
}
}];
if (!_dataList) {
[self endRefresh:^{
NSString *url = sourceDic[@"nextUrl"];
self.nextUrl = url;
self.dataList = tempArray;
} completion:^{
}];
}else {
[self endRefresh:^{
NSString *url = sourceDic[@"nextUrl"];
self.nextUrl = url;
self.dataList = tempArray;
} completion:^{
}];
}
}else {
[self endRefresh:^{
NSString *url = sourceDic[@"nextUrl"];
self.nextUrl = url;
self.dataList = [NSMutableArray array];
} completion:^{
}];
TPLOG(@"文章列表为空");
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NEEDREFRESHENTERFORGROUND object:nil];
[self.dataList removeAllObjects];
self.infoDic = nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
|