Commit fa8973524d44c5506d09eb567cbd67d598a7f2c1

Authored by yanglingyu
1 parent ba0c3a16

英文首页缓存,国新之声下拉刷新逻辑修改

CNLiveScioLive/Pages/Home/CNHomeENViewController.m
... ... @@ -41,6 +41,10 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell";
41 41 NSLog(@"%@",parameters);
42 42  
43 43 if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
  44 + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"ENHome"];
  45 + if (data && self.pageNo == 1) {
  46 + [self dealDictionaryData:data];
  47 + }
44 48 [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
45 49 [self.tableView.mj_header endRefreshing];
46 50 [self.tableView.mj_footer endRefreshing];
... ... @@ -57,60 +61,16 @@ static NSString *newsUpPicTableViewCell = @"CNLiveNewsUpPicTableViewCell";
57 61 NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json];
58 62  
59 63 if ([dic[@"errorCode"] isEqualToString:@"0"]) {
60   - if ([dic[@"programs"] isKindOfClass:[NSArray class]]) {
61   -
62   - NSArray *lists = dic[@"programs"];
63   - if(self->_pageNo == 1&&lists.count > 0){
64   - [self.data removeAllObjects];
65   -
66   - }
67   - self->_pageNo++;
68   - for (NSDictionary *dics in lists) {
69   - [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
70   - return @{ @"ID" : @"id" ,@"Description" : @"description" };
71   - }];
72   - NSLog(@"%@",dics);
73   - [self.data addObject:[CNHomeModel mj_objectWithKeyValues:dics]];
74   -
75   - }
76   -
  64 + NSData *data = [dic mj_JSONData];
  65 + if (self.pageNo==1) {
  66 + [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"ENHome"];
77 67 }
78   - NSDictionary *ttName = dic[@"ttName"];
79   - NSArray *programs = ttName[@"programs"];
80   -
81   - if ([programs isKindOfClass:[NSArray class]]) {
82   - [self.banner removeAllObjects];
83   - for (NSDictionary *dics in programs) {
84   - [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
85   - return @{ @"ID" : @"id" ,@"Description" : @"description" };
86   - }];
87   -
88   - NSLog(@"%@",dics);
89   - [self.banner addObject:[CNHomeModel mj_objectWithKeyValues:dics]];
90   - }
91   -
92   - NSMutableArray *titles = [NSMutableArray array];
93   - NSMutableArray *imagesURLStrings = [NSMutableArray array];
94   - for(int i = 0; i < self.banner.count; i++){
95   - CNHomeModel *model = self.banner[i];
96   - [titles addObject:model.title];
97   - [imagesURLStrings addObject:model.img];
98   -
99   - }
100   - if (titles.count!=0) {
101   - self.tableView.tableHeaderView = self.cycleScrollView;
102   - self.cycleScrollView.titlesGroup = titles;
103   - self.cycleScrollView.imageURLStringsGroup = imagesURLStrings;
104   - }
105   -
106   - }else
107   - {
108   - if (self.pageNo == 2) {
109   - self.tableView.tableHeaderView = nil;
110   - }
111   - }
112   -
  68 + [self dealDictionaryData:data];
113 69 } else {
  70 + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"ENHome"];
  71 + if (data && self.pageNo == 1) {
  72 + [self dealDictionaryData:data];
  73 + }
114 74 [AlertViewTool showHUDViewText:dic[@"errorMessage"]];
115 75  
116 76 }
... ... @@ -123,18 +83,78 @@ static NSString *newsUpPicTableViewCell = @&quot;CNLiveNewsUpPicTableViewCell&quot;;
123 83 [self.tableView.mj_footer endRefreshing];
124 84  
125 85 }
126   - [self.tableView reloadData];
  86 +
127 87 self->_isRefreshing = NO;
128 88  
129 89  
130 90 } failure:^(NSError *error) {
  91 + NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"ENHome"];
  92 + if (data && self.pageNo == 1) {
  93 + [self dealDictionaryData:data];
  94 + }
131 95 [AlertViewTool hideHUDView];
132 96 self->_isRefreshing = NO;
133 97 [AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
134 98  
135 99 }];
136 100 }
  101 +-(void)dealDictionaryData:(NSData *)data
  102 +{
  103 + NSDictionary *dic = [data mj_JSONObject];
  104 + if ([dic[@"programs"] isKindOfClass:[NSArray class]]) {
  105 +
  106 + NSArray *lists = dic[@"programs"];
  107 + if(self->_pageNo == 1&&lists.count > 0){
  108 + [self.data removeAllObjects];
  109 +
  110 + }
  111 + self->_pageNo++;
  112 + for (NSDictionary *dics in lists) {
  113 + [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
  114 + return @{ @"ID" : @"id" ,@"Description" : @"description" };
  115 + }];
  116 + NSLog(@"%@",dics);
  117 + [self.data addObject:[CNHomeModel mj_objectWithKeyValues:dics]];
  118 +
  119 + }
  120 +
  121 + }
  122 + NSDictionary *ttName = dic[@"ttName"];
  123 + NSArray *programs = ttName[@"programs"];
  124 +
  125 + if ([programs isKindOfClass:[NSArray class]]) {
  126 + [self.banner removeAllObjects];
  127 + for (NSDictionary *dics in programs) {
  128 + [CNHomeModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
  129 + return @{ @"ID" : @"id" ,@"Description" : @"description" };
  130 + }];
  131 +
  132 + NSLog(@"%@",dics);
  133 + [self.banner addObject:[CNHomeModel mj_objectWithKeyValues:dics]];
  134 + }
  135 +
  136 + NSMutableArray *titles = [NSMutableArray array];
  137 + NSMutableArray *imagesURLStrings = [NSMutableArray array];
  138 + for(int i = 0; i < self.banner.count; i++){
  139 + CNHomeModel *model = self.banner[i];
  140 + [titles addObject:model.title];
  141 + [imagesURLStrings addObject:model.img];
137 142  
  143 + }
  144 + if (titles.count!=0) {
  145 + self.tableView.tableHeaderView = self.cycleScrollView;
  146 + self.cycleScrollView.titlesGroup = titles;
  147 + self.cycleScrollView.imageURLStringsGroup = imagesURLStrings;
  148 + }
  149 +
  150 + }else
  151 + {
  152 + if (self.pageNo == 2) {
  153 + self.tableView.tableHeaderView = nil;
  154 + }
  155 + }
  156 + [self.tableView reloadData];
  157 +}
138 158 - (void)loadUpData{
139 159 _pageNo = 1;
140 160 if(!_isRefreshing){
... ...
CNLiveScioLive/Pages/Newsound/OldController/VoiceViewController.m
... ... @@ -681,7 +681,7 @@ static const NSInteger margin = 34;
681 681 [self.view addSubview:self.tableView];
682 682  
683 683 //设置下拉刷新
684   - MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadVoice)];
  684 + MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadVoiceData)];
685 685 [header setImages:refreshingImages forState:MJRefreshStateRefreshing];
686 686 header.lastUpdatedTimeLabel.hidden = YES;
687 687 header.stateLabel.hidden = YES;
... ... @@ -708,7 +708,7 @@ static const NSInteger margin = 34;
708 708 [self.view addSubview:self.enTableView];
709 709  
710 710 //设置下拉刷新
711   - MJRefreshGifHeader *engHeader = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadVOS)];
  711 + MJRefreshGifHeader *engHeader = [MJRefreshGifHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadVOSData)];
712 712 [engHeader setImages:refreshingImages forState:MJRefreshStateRefreshing];
713 713 engHeader.lastUpdatedTimeLabel.hidden = YES;
714 714 engHeader.stateLabel.hidden = YES;
... ...