YHPJzqViewController.m 9.9 KB

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