SystemmessageViewController.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // SystemmessageViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2017/12/9.
  6. // Copyright © 2017年 罗云飞. All rights reserved.
  7. //
  8. #import "SystemmessageViewController.h"
  9. #import "SystemmessageCell.h"
  10. #import "SystemModel.h"
  11. #import "SystemDetailViewController.h"
  12. @interface SystemmessageViewController ()<UITableViewDelegate,UITableViewDataSource>{
  13. UITableView *newtableView;
  14. NSMutableArray *dataArray;
  15. int pageNo;
  16. }
  17. @end
  18. @implementation SystemmessageViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self setNavTitle:@"系统消息"];
  22. [self dataInitialization];
  23. [self SystemmessageNetworkrequest:nil];
  24. [self loadsView];
  25. [self addRefreshing];
  26. // Do any additional setup after loading the view.
  27. }
  28. #pragma mark -----系统列表网络请求------
  29. - (void)SystemmessageNetworkrequest:(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. [parameters safeSetObject:@"1" forKey:@"subject"];//消息类型 1-系统消息 ,2-推荐消息
  42. [NetworkRequestManager requestPostWithInterfacePrefix:JT_listMessage parameters:parameters onSuccess:^(id requestData) {
  43. [self dismiss:object];
  44. NSLog(@"服务器返回数据:%@",requestData);
  45. if ([requestData[@"error"] count] !=0) {
  46. for (NSDictionary *dic in requestData[@"error"]) {
  47. [MBProgressHUD showError:dic[@"message"] toView:self.view];
  48. }
  49. }else{
  50. pageNo = pageNumberIndex;
  51. if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {//下拉要清空数组
  52. [dataArray removeAllObjects];
  53. }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {//上拉
  54. if ([requestData[@"data"][@"list"] count]<=0) {
  55. [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom];
  56. }
  57. }
  58. for (NSDictionary *dic in requestData[@"data"][@"list"]) {
  59. SystemModel *model = [[SystemModel alloc] initWithDictionary:dic error:nil];
  60. [dataArray addObject:model];
  61. }
  62. //查询不到类型底图
  63. if (dataArray.count<=0) {
  64. [self addErrorLoadingFrame:CGRectMake(0, NavHeader, newtableView.width, newtableView.height) title:@"系统还未给您推送消息哦" buttonTitle:nil imageString:NewNoDataErrorImage];
  65. }else {
  66. [self hideReloadingview];
  67. [newtableView reloadData];
  68. }
  69. }
  70. } onFailure:^{
  71. [self dismiss:object];
  72. }];
  73. }
  74. #pragma mark - 数据初始化
  75. - (void)dataInitialization{
  76. dataArray = NewMutableArrayInit;
  77. pageNo = 1;
  78. }
  79. #pragma mark ----加载界面
  80. - (void)loadsView{
  81. [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]];
  82. newtableView.separatorStyle = NO;
  83. }
  84. #pragma mark-------------------------UITableView------------------------------------
  85. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  86. {
  87. return 1;
  88. }
  89. //返回每段行数
  90. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  91. {
  92. return dataArray.count;
  93. }
  94. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  95. {
  96. static NSString *Cell = @"Cell";
  97. SystemmessageCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  98. if (cell == nil) {
  99. cell = [[SystemmessageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  100. }
  101. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  102. cell.accessoryType = UITableViewCellAccessoryNone;
  103. [cell assignment:dataArray[indexPath.row]];
  104. if (indexPath.row == dataArray.count-1) {
  105. cell.line.hidden = YES;
  106. }
  107. return cell;
  108. }
  109. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  110. {
  111. return fitScreenWidth(67);
  112. }
  113. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  114. SystemModel *model = dataArray[indexPath.row];
  115. SystemDetailViewController *vc = [[SystemDetailViewController alloc] init];
  116. vc.messageId = model.messageId;
  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 10;
  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 *newvc = newtableView;
  136. newvc.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  137. if ([NetworkRequestManager connectedToNetwork]) {
  138. [weakSelf SystemmessageNetworkrequest:newvc.mj_header];
  139. }else{
  140. [newvc.mj_header endRefreshing];
  141. }
  142. }];
  143. newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  144. if ([NetworkRequestManager connectedToNetwork]) {
  145. [weakSelf SystemmessageNetworkrequest:newvc.mj_footer];
  146. }else{
  147. [newvc.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. - (void)didReceiveMemoryWarning {
  164. [super didReceiveMemoryWarning];
  165. // Dispose of any resources that can be recreated.
  166. }
  167. /*
  168. #pragma mark - Navigation
  169. // In a storyboard-based application, you will often want to do a little preparation before navigation
  170. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  171. // Get the new view controller using [segue destinationViewController].
  172. // Pass the selected object to the new view controller.
  173. }
  174. */
  175. @end