ZCBKViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. //
  2. // ZCBKViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/8/19.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "ZCBKViewController.h"
  9. #import "ZCBKCell.h"
  10. #import "ZCJDModel.h"
  11. #import "TongyongDetailViewController.h"
  12. #import "FaDetaiH5ViewController.h"
  13. #import "FaXianDetailViewController.h"
  14. @interface ZCBKViewController ()<UITableViewDelegate,UITableViewDataSource>{
  15. UITableView *newtableView;
  16. NSMutableArray *dataArray;
  17. int pageIndex;
  18. int pageSize;
  19. int pageNumber;
  20. UIView *showView;
  21. }
  22. @end
  23. @implementation ZCBKViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self setNavTitle:@"知产百科"];
  27. [self dataInitialization];
  28. [self loadsView];
  29. [self addRefreshing];
  30. [self networkRequest:nil];
  31. // Do any additional setup after loading the view.
  32. }
  33. - (void)dataInitialization{
  34. dataArray = NewMutableArrayInit;
  35. pageIndex = 1;
  36. pageSize = 10;
  37. pageNumber = 1;
  38. }
  39. - (void)networkRequest:(id)object
  40. {
  41. int pageNumberIndex=1;
  42. if (!object) {
  43. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  44. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  45. pageNumberIndex = 1;
  46. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  47. pageNumberIndex = pageNumber+1;
  48. }
  49. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  50. [parameters safeSetObject:@(pageSize) forKey:@"pageSize"];
  51. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];
  52. [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewlistEncyclopedia parameters:parameters onSuccess:^(id requestData) {
  53. [self dismiss:object];
  54. if ([requestData[@"error"] count] !=0) {
  55. for (NSDictionary *dic in requestData[@"error"]) {
  56. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  57. }
  58. }else{
  59. pageNumber = pageNumberIndex;
  60. if ([object isKindOfClass:[MJRefreshNormalHeader class]] || pageNumber==1) {
  61. [dataArray removeAllObjects];
  62. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  63. NSMutableArray *arr = requestData[@"data"][@"list"];
  64. if ([arr count]<=0) {
  65. [[[UIApplication sharedApplication].delegate window] makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  66. return;
  67. }
  68. }
  69. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  70. ZCJDModel *model = [[ZCJDModel alloc] initWithDictionary:dic error:nil];
  71. [dataArray addObject:model];
  72. }
  73. //查询不到类型底图
  74. if (dataArray.count<=0) {
  75. [self addErrorLoadingFrame:CGRectMake(0, NavHeader, newtableView.width, newtableView.height) title:@"暂无订单" buttonTitle:nil imageString:NewNoDataErrorImage];
  76. }else {
  77. [self hideReloadingview];
  78. [newtableView reloadData];
  79. }
  80. }
  81. } onFailure:^{
  82. [self dismiss:object];
  83. }];
  84. }
  85. #pragma mark ----加载界面
  86. - (void)loadsView{
  87. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader) backgroundColor:NewGroupTableViewBackgroundColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  88. newtableView.separatorStyle = NO;
  89. }
  90. #pragma mark-------------------------UITableView------------------------------------
  91. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  92. {
  93. return 1;
  94. }
  95. //返回每段行数
  96. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  97. {
  98. return dataArray.count;
  99. }
  100. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  101. {
  102. static NSString *Cell = @"Cell";
  103. ZCBKCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  104. if (cell == nil) {
  105. cell = [[ZCBKCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  106. }
  107. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  108. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  109. if (dataArray.count>0) {
  110. ZCJDModel *model = dataArray[indexPath.row];
  111. cell.title.text = model.title;
  112. }
  113. return cell;
  114. }
  115. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  116. {
  117. return 45;
  118. }
  119. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  120. if (dataArray.count>0) {
  121. ZCJDModel *model = dataArray[indexPath.row];
  122. // TongyongDetailViewController *vc = [[TongyongDetailViewController alloc] init];
  123. // vc.title = model.title;
  124. // vc.neirong = model.content;
  125. // vc.time = model.releaseDate;
  126. // vc.type = @"百科";
  127. // NewPushViewController(vc);
  128. // FaDetaiH5ViewController *vc = [[FaDetaiH5ViewController alloc] init];
  129. // vc.type = @"资讯";
  130. // vc.ID = model.ID;
  131. // NewPushViewController(vc);
  132. FaXianDetailViewController *vc = [FaXianDetailViewController new];
  133. vc.title = model.title;
  134. vc.neirong = model.content;
  135. vc.time = model.releaseDate;
  136. vc.type = @"百科";
  137. vc.titleimg = model.titleImg;
  138. NewPushViewController(vc);
  139. }
  140. }
  141. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  142. return CGFLOAT_MIN;
  143. }
  144. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  145. return CGFLOAT_MIN;
  146. }
  147. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  148. return [[UIView alloc] init];
  149. }
  150. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  151. return [[UIView alloc] init];
  152. }
  153. #pragma mark - 上拉下拉初始化
  154. - (void)addRefreshing
  155. {
  156. __weak typeof(self) weakSelf = self;
  157. __weak UITableView *tableView = newtableView;
  158. tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  159. if ([NetworkRequestManager connectedToNetwork]) {
  160. [weakSelf networkRequest:tableView.mj_header];
  161. }else{
  162. [tableView.mj_header endRefreshing];
  163. }
  164. }];
  165. tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  166. if ([NetworkRequestManager connectedToNetwork]) {
  167. [weakSelf networkRequest:tableView.mj_footer];
  168. }else{
  169. [tableView.mj_footer endRefreshing];
  170. }
  171. }];
  172. }
  173. - (void)dismiss:(id)object
  174. {
  175. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  176. __weak UITableView *newvc = newtableView;
  177. [newvc.mj_header endRefreshing];
  178. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  179. __weak UITableView *newvc = newtableView;
  180. [newvc.mj_footer endRefreshing];
  181. }else {
  182. [MBProgressHUD hideHUDForView:self.view];
  183. }
  184. }
  185. #pragma mark- 外部触发自动刷新
  186. - (void)autoDownRefresh
  187. {
  188. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  189. [self autoRefresh];
  190. });
  191. }
  192. #pragma mark- 网络请求
  193. - (void)autoRefresh
  194. {
  195. __weak UITableView *tableView = newtableView;
  196. [tableView.mj_header beginRefreshing];
  197. }
  198. #pragma mark 初始化展示框
  199. - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  200. {
  201. if(!showView)
  202. {
  203. [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  204. [showView setHidden:NO];
  205. [showView setBackgroundColor:NewBgGrayColor];
  206. UIImage *NOimg = [UIImage imageNamed:image];
  207. UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
  208. [showView addSubview:tempIcon];
  209. tempIcon.sd_layout
  210. .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
  211. .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
  212. .widthIs(NOimg.size.width/2.0f)
  213. .heightIs(NOimg.size.height/2.0f);
  214. UILabel *tipLab = [UILabel new];
  215. [showView addSubview:tipLab];
  216. [tipLab setText:text];
  217. [tipLab setTextAlignment:NSTextAlignmentCenter];
  218. [tipLab setTextColor:NewLightGrayColor];
  219. [tipLab setBackgroundColor:NewClearColor];
  220. [tipLab setFont:NewAutoFont(16.0)];
  221. tipLab.sd_layout
  222. .leftEqualToView(showView)
  223. .rightEqualToView(showView)
  224. .topSpaceToView(tempIcon,10)
  225. .heightIs(20.0);
  226. if (buttonText.length>0) {
  227. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  228. [showView addSubview:button];
  229. [button setTitle:buttonText forState:UIControlStateNormal];
  230. [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
  231. ViewBorderRadius(button, 16, 2, NewNavigationColor);
  232. [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
  233. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
  234. button.sd_layout
  235. .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
  236. .topSpaceToView(tipLab, 30.0)
  237. .widthIs(width+35)
  238. .heightIs(34);
  239. }
  240. }
  241. [UIView beginAnimations:@"ShowArrow" context:nil];
  242. [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  243. [UIView setAnimationDuration:0.25f];
  244. [UIView setAnimationDelegate:self];
  245. [showView setAlpha:1.0f];
  246. [UIView commitAnimations];
  247. }
  248. - (void)hideReloadingview
  249. {
  250. [UIView animateWithDuration:0.25 animations:^{
  251. showView.hidden = YES;
  252. } completion:^(BOOL finished) {
  253. for (id obj in showView.subviews) {
  254. [obj removeFromSuperview];
  255. }
  256. showView = nil;
  257. [showView removeFromSuperview];
  258. }];
  259. }
  260. - (void)didReceiveMemoryWarning {
  261. [super didReceiveMemoryWarning];
  262. // Dispose of any resources that can be recreated.
  263. }
  264. /*
  265. #pragma mark - Navigation
  266. // In a storyboard-based application, you will often want to do a little preparation before navigation
  267. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  268. // Get the new view controller using [segue destinationViewController].
  269. // Pass the selected object to the new view controller.
  270. }
  271. */
  272. @end