MyresultsViewController.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //
  2. // MyresultsViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/8.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "MyresultsViewController.h"
  9. #import "MyresultsCell.h"
  10. #import "MyresultsModel.h"
  11. #import "AchievementsdetailViewController.h"
  12. @interface MyresultsViewController ()<UITableViewDelegate,UITableViewDataSource>{
  13. UITableView *newtableView;
  14. NSMutableArray *dataArray;
  15. int pageNo;
  16. }
  17. @end
  18. @implementation MyresultsViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self setNavTitle:@"我的成果"];
  22. [self dataInitialization];
  23. [self MyresultsNetworkrequest:nil];
  24. [self loadsView];
  25. [self addRefreshing];
  26. // Do any additional setup after loading the view.
  27. }
  28. #pragma mark -----我的成果列表网络请求------
  29. - (void)MyresultsNetworkrequest:(id)object {
  30. int pageNumberIndex=1;
  31. if (!object) {
  32. [MBProgressHUD showLoadToView:self.view title:@"请稍后..."];
  33. }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  34. pageNumberIndex = 1;
  35. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {
  36. pageNumberIndex = pageNo+1;
  37. }
  38. NSMutableDictionary *parameters = NewMutableDictionaryInit;
  39. [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];//页码
  40. [parameters safeSetObject:@"10" forKey:@"pageSize"];//页面显示数
  41. [NetworkRequestManager requestGetWithInterfacePrefix:JT_MyachievementList parameters:parameters onSuccess:^(id requestData) {
  42. [self dismiss:object];
  43. NSLog(@"服务器返回数据:%@",requestData);
  44. if ([requestData[@"error"] count] !=0) {
  45. for (NSDictionary *dic in requestData[@"error"]) {
  46. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  47. }
  48. }else{
  49. pageNo = pageNumberIndex;
  50. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {//下拉要清空数组
  51. [dataArray removeAllObjects];
  52. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {//上拉
  53. if ([requestData[@"data"][@"list"] count]<=0) {
  54. [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  55. }
  56. }
  57. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  58. MyresultsModel *model = [[MyresultsModel alloc] initWithDictionary:dic error:nil];
  59. [dataArray addObject:model];
  60. }
  61. //查询不到类型底图
  62. if (dataArray.count<=0) {
  63. [self addErrorLoadingFrame:CGRectMake(0, NavHeader, newtableView.width, newtableView.height) title:@"咦,您还没有成果噢" buttonTitle:nil imageString:NewNoDataErrorImage];
  64. }else {
  65. [self hideReloadingview];
  66. [newtableView reloadData];
  67. }
  68. }
  69. } onFailure:^{
  70. [self dismiss:object];
  71. }];
  72. }
  73. #pragma mark - 数据初始化
  74. - (void)dataInitialization{
  75. dataArray = NewMutableArrayInit;
  76. pageNo = 1;
  77. }
  78. #pragma mark ----加载界面
  79. - (void)loadsView{
  80. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader) backgroundColor:NewNavigationColor style:UITableViewStyleGrouped delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  81. newtableView.separatorStyle = NO;
  82. }
  83. #pragma mark-------------------------UITableView------------------------------------
  84. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  85. {
  86. return 1;
  87. }
  88. //返回每段行数
  89. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  90. {
  91. return dataArray.count;
  92. }
  93. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  94. {
  95. static NSString *Cell = @"Cell";
  96. MyresultsCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  97. if (cell == nil) {
  98. cell = [[MyresultsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  99. }
  100. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  101. cell.accessoryType = UITableViewCellAccessoryNone;
  102. if (dataArray.count>0) {
  103. [cell assignment:dataArray[indexPath.row]];
  104. }
  105. return cell;
  106. }
  107. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  108. {
  109. return fitScreenWidth(142);
  110. }
  111. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  112. MyresultsModel *model = dataArray[indexPath.row];
  113. AchievementsdetailViewController *vc = [[AchievementsdetailViewController alloc] init];
  114. vc.ID = model.ID;
  115. NewPushViewController(vc);
  116. }
  117. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  118. return CGFLOAT_MIN;
  119. }
  120. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  121. return CGFLOAT_MIN;
  122. }
  123. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  124. return [[UIView alloc] init];
  125. }
  126. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  127. return [[UIView alloc] init];
  128. }
  129. #pragma mark - 上拉下拉初始化
  130. - (void)addRefreshing
  131. {
  132. __weak typeof(self) weakSelf = self;
  133. __weak UITableView *newvc = newtableView;
  134. newvc.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  135. if ([NetworkRequestManager connectedToNetwork]) {
  136. [weakSelf MyresultsNetworkrequest:newvc.mj_header];
  137. }else{
  138. [newvc.mj_header endRefreshing];
  139. }
  140. }];
  141. newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  142. if ([NetworkRequestManager connectedToNetwork]) {
  143. [weakSelf MyresultsNetworkrequest:newvc.mj_footer];
  144. }else{
  145. [newvc.mj_footer endRefreshing];
  146. }
  147. }];
  148. }
  149. - (void)dismiss:(id)object
  150. {
  151. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {
  152. __weak UITableView *newvc = newtableView;
  153. [newvc.mj_header endRefreshing];
  154. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){
  155. __weak UITableView *newvc = newtableView;
  156. [newvc.mj_footer endRefreshing];
  157. }else {
  158. [MBProgressHUD hideHUDForView:self.view];
  159. }
  160. }
  161. - (void)didReceiveMemoryWarning {
  162. [super didReceiveMemoryWarning];
  163. // Dispose of any resources that can be recreated.
  164. }
  165. /*
  166. #pragma mark - Navigation
  167. // In a storyboard-based application, you will often want to do a little preparation before navigation
  168. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  169. // Get the new view controller using [segue destinationViewController].
  170. // Pass the selected object to the new view controller.
  171. }
  172. */
  173. @end