热更新demo

channalPoliticsController.m 6.6KB

    // // UITestViewController.m // ThePaperDemo // // Created by Scar on 14-9-3. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "channalPoliticsController.h" @interface channalPoliticsController () { } @end @implementation channalPoliticsController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.dataKey = @"contList"; } - (void)pullRefreshHandler { [self remoteAction]; } - (void)pullLoadMoreHander { [Remote doJsonAction:2 requestUrl:self.nextUrl parameter:nil delegate:self]; } - (void)remoteAction { if (self.nodeId) { NSDictionary *dic = @{@"n":self.nodeId}; [Remote doJsonAction:1 requestUrl:channelNodeListURL parameter:dic delegate:self]; } } - (void)startWaitCursor:(int)actionTag { } - (void)stopWaitCursor:(int)actionTag { } - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if (actionTag == 1) { [self getRefreshDataFromDic:responsData sourceKey:self.dataKey contentClass:self.dataClass]; [self saveRemoteDataToCoreData:responsData]; [self endRefresh]; }else { NSLog(@"return load data!"); NSArray *contList = responsData[@"contList"]; if (contList && contList.count > 0) { NSMutableArray *oriListData = [NSMutableArray arrayWithArray:self.dataList]; NSMutableArray *tempArray = [NSMutableArray array]; [contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { listContObjectVO *contentBO = setJsonDicToDataModel(obj, [listContObjectVO class]); if ([contentBO isKindOfClass:[listContObjectVO class]]) { listContObjectVO *list = contentBO; if ([list.cardMode intValue] != ChildListCardType) { if ([list.cardMode intValue] == HeadCardType || [list.cardMode intValue] == BigCardType || [list.cardMode intValue] == SmallCardType || [list.cardMode intValue] == HotAskCardType || [list.cardMode intValue] == AdCardType){ // if ([list.cardMode intValue] == AdCardType) { // list.adUrl = @"http://ad.thepaper.cn/s?z=paper&c=1104&op=1"; // } if ([[TPUserDefault instance].readModeStr intValue] == imageMode) { [tempArray addObject:list]; }else if ([[TPUserDefault instance].readModeStr intValue] == textMode) { if (![list.forwordType intValue] == imageNewsForwardType) { [tempArray addObject:list]; } }else { if ([Remote IsEnableWIFI]) { [tempArray addObject:list]; }else { if (![list.forwordType intValue] == imageNewsForwardType) { [tempArray addObject:list]; } } } }else if ([list.cardMode intValue] == HotTopicListType){ [tempArray addObject:list.title?list.title:@""]; [list.childList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { TopicInfoBO *topicInfoBO = setJsonDicToDataModel(obj, [TopicInfoBO class]); [tempArray addObject:topicInfoBO]; }]; } }else if ([list.cardMode intValue] == ChildListCardType){ [tempArray addObject:list.title?list.title:@""]; [list.childList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { listContObjectVO *childListBO = setJsonDicToDataModel(obj, [listContObjectVO class]); childListBO.isChildList = @"1"; if ([[TPUserDefault instance].readModeStr intValue] == imageMode) { [tempArray addObject:childListBO]; }else if ([[TPUserDefault instance].readModeStr intValue] == textMode) { if (![list.forwordType intValue] == imageNewsForwardType) { [tempArray addObject:childListBO]; } }else { if ([Remote IsEnableWIFI]) { [tempArray addObject:childListBO]; }else { if (![list.forwordType intValue] == imageNewsForwardType) { [tempArray addObject:childListBO]; } } } }]; } }else { [tempArray addObject:contentBO]; } }]; NSInteger firstIndex = self.dataList.count; [oriListData addObjectsFromArray:tempArray]; self.needReload = NO; self.dataList = oriListData; NSMutableArray *indexList = [NSMutableArray array]; for (NSInteger i = firstIndex;i<self.dataList.count;i++) { [indexList addObject:[NSIndexPath indexPathForRow:i inSection:0]]; } [self.tableView beginUpdates]; [self.tableView insertRowsAtIndexPaths:indexList withRowAnimation:UITableViewRowAnimationFade]; [self.tableView endUpdates]; [self loadSuccess]; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; }else { TPLOG(@"加载数据为空"); [self loadFailed]; } } } - (void)dealloc { } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end