GWPJViewController.m 9.9 KB

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