DemandViewController.m 10 KB

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