AchievementsViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. //
  2. // AchievementsViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/9.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "AchievementsViewController.h"
  9. #import "MyattentionCell.h"
  10. #import "MyattentionModel.h"
  11. #import "DemanddetailViewController.h"
  12. @interface AchievementsViewController ()<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 AchievementsViewController
  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:@"1" 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. if (dataArray.count>0) {
  159. [cell assignment:dataArray[indexPath.row]];
  160. }
  161. return cell;
  162. }
  163. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  164. {
  165. return fitScreenWidth(67);
  166. }
  167. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  168. MyattentionModel *model = dataArray[indexPath.row];
  169. DemanddetailViewController *vc = [[DemanddetailViewController alloc] init];
  170. vc.ID = model.ID;
  171. NewPushViewController(vc);
  172. }
  173. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  174. return CGFLOAT_MIN;
  175. }
  176. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  177. return 10;
  178. }
  179. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  180. return [[UIView alloc] init];
  181. }
  182. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  183. return [[UIView alloc] init];
  184. }
  185. #pragma mark 初始化展示框
  186. - (void) addErrorLoadingFrame:(CGRect)frame title:(NSString *)text buttonTitle:(NSString *)buttonText imageString:(NSString *)image
  187. {
  188. if(!showView)
  189. {
  190. [self.view addSubview:showView = [[UIView alloc] initWithFrame:frame]];
  191. [showView setHidden:NO];
  192. [showView setBackgroundColor:NewBgGrayColor];
  193. UIImage *NOimg = [UIImage imageNamed:image];
  194. UIImageView *tempIcon = [[UIImageView alloc]initWithImage:NOimg];
  195. [showView addSubview:tempIcon];
  196. tempIcon.sd_layout
  197. .leftSpaceToView(showView, (showView.width/2)-(NOimg.size.width/4.0f))
  198. .topSpaceToView(showView, (showView.height/2)-100.0f-(NOimg.size.height/4.0f))
  199. .widthIs(NOimg.size.width/2.0f)
  200. .heightIs(NOimg.size.height/2.0f);
  201. UILabel *tipLab = [UILabel new];
  202. [showView addSubview:tipLab];
  203. [tipLab setText:text];
  204. [tipLab setTextAlignment:NSTextAlignmentCenter];
  205. [tipLab setTextColor:NewLightGrayColor];
  206. [tipLab setBackgroundColor:NewClearColor];
  207. [tipLab setFont:NewAutoFont(16.0)];
  208. tipLab.sd_layout
  209. .leftEqualToView(showView)
  210. .rightEqualToView(showView)
  211. .topSpaceToView(tempIcon,10)
  212. .heightIs(20.0);
  213. if (buttonText.length>0) {
  214. UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
  215. [showView addSubview:button];
  216. [button setTitle:buttonText forState:UIControlStateNormal];
  217. [button setTitleColor:NewNavigationColor forState:UIControlStateNormal];
  218. ViewBorderRadius(button, 16, 2, NewNavigationColor);
  219. [button addTarget:self action:@selector(reloadingData) forControlEvents:UIControlEventTouchUpInside];
  220. CGFloat width = [NewUtils heightforString:[NSString stringWithFormat:@"%@",buttonText] andHeight:34 fontSize:16];
  221. button.sd_layout
  222. .leftSpaceToView(showView, (showView.width/2)-((width+35)/2))
  223. .topSpaceToView(tipLab, 30.0)
  224. .widthIs(width+35)
  225. .heightIs(34);
  226. }
  227. }
  228. [UIView beginAnimations:@"ShowArrow" context:nil];
  229. [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
  230. [UIView setAnimationDuration:0.25f];
  231. [UIView setAnimationDelegate:self];
  232. [showView setAlpha:1.0f];
  233. [UIView commitAnimations];
  234. }
  235. - (void)hideReloadingview
  236. {
  237. [UIView animateWithDuration:0.25 animations:^{
  238. showView.hidden = YES;
  239. } completion:^(BOOL finished) {
  240. for (id obj in showView.subviews) {
  241. [obj removeFromSuperview];
  242. }
  243. showView = nil;
  244. [showView removeFromSuperview];
  245. }];
  246. }
  247. - (void)didReceiveMemoryWarning {
  248. [super didReceiveMemoryWarning];
  249. // Dispose of any resources that can be recreated.
  250. }
  251. /*
  252. #pragma mark - Navigation
  253. // In a storyboard-based application, you will often want to do a little preparation before navigation
  254. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  255. // Get the new view controller using [segue destinationViewController].
  256. // Pass the selected object to the new view controller.
  257. }
  258. */
  259. @end