// // SystemmessageViewController.m // jitao // // Created by 罗云飞 on 2017/12/9. // Copyright © 2017年 罗云飞. All rights reserved. // #import "SystemmessageViewController.h" #import "SystemmessageCell.h" #import "SystemModel.h" #import "SystemDetailViewController.h" @interface SystemmessageViewController (){ UITableView *newtableView; NSMutableArray *dataArray; int pageNo; } @end @implementation SystemmessageViewController - (void)viewDidLoad { [super viewDidLoad]; [self setNavTitle:@"系统消息"]; [self dataInitialization]; [self SystemmessageNetworkrequest:nil]; [self loadsView]; [self addRefreshing]; // Do any additional setup after loading the view. } #pragma mark -----系统列表网络请求------ - (void)SystemmessageNetworkrequest:(id)object { int pageNumberIndex=1; if (!object) { [MBProgressHUD showLoadToView:self.view title:@"请稍后..."]; }else if ([object isKindOfClass:[MJRefreshNormalHeader class]]) { pageNumberIndex = 1; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) { pageNumberIndex = pageNo+1; } NSMutableDictionary *parameters = NewMutableDictionaryInit; [parameters safeSetObject:@(pageNumberIndex) forKey:@"pageNo"];//页码 [parameters safeSetObject:@"10" forKey:@"pageSize"];//页面显示数 [parameters safeSetObject:@"1" forKey:@"subject"];//消息类型 1-系统消息 ,2-推荐消息 [NetworkRequestManager requestPostWithInterfacePrefix:JT_listMessage parameters:parameters onSuccess:^(id requestData) { [self dismiss:object]; NSLog(@"服务器返回数据:%@",requestData); if ([requestData[@"error"] count] !=0) { for (NSDictionary *dic in requestData[@"error"]) { [MBProgressHUD showError:dic[@"message"] toView:self.view]; } }else{ pageNo = pageNumberIndex; if ([object isKindOfClass:[MJRefreshNormalHeader class]]) {//下拉要清空数组 [dataArray removeAllObjects]; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]) {//上拉 if ([requestData[@"data"][@"list"] count]<=0) { [self.view makeToast:NewConnectServerNoMoreDataTitle duration:1.0 position:CSToastPositionBottom]; } } for (NSDictionary *dic in requestData[@"data"][@"list"]) { SystemModel *model = [[SystemModel alloc] initWithDictionary:dic error:nil]; [dataArray addObject:model]; } //查询不到类型底图 if (dataArray.count<=0) { [self addErrorLoadingFrame:CGRectMake(0, NavHeader, newtableView.width, newtableView.height) title:@"系统还未给您推送消息哦" buttonTitle:nil imageString:NewNoDataErrorImage]; }else { [self hideReloadingview]; [newtableView reloadData]; } } } onFailure:^{ [self dismiss:object]; }]; } #pragma mark - 数据初始化 - (void)dataInitialization{ dataArray = NewMutableArrayInit; pageNo = 1; } #pragma mark ----加载界面 - (void)loadsView{ [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]]; newtableView.separatorStyle = NO; } #pragma mark-------------------------UITableView------------------------------------ -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } //返回每段行数 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *Cell = @"Cell"; SystemmessageCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell]; if (cell == nil) { cell = [[SystemmessageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果) cell.accessoryType = UITableViewCellAccessoryNone; [cell assignment:dataArray[indexPath.row]]; if (indexPath.row == dataArray.count-1) { cell.line.hidden = YES; } return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return fitScreenWidth(67); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ SystemModel *model = dataArray[indexPath.row]; SystemDetailViewController *vc = [[SystemDetailViewController alloc] init]; vc.messageId = model.messageId; NewPushViewController(vc); } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 10; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return [[UIView alloc] init]; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [[UIView alloc] init]; } #pragma mark - 上拉下拉初始化 - (void)addRefreshing { __weak typeof(self) weakSelf = self; __weak UITableView *newvc = newtableView; newvc.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf SystemmessageNetworkrequest:newvc.mj_header]; }else{ [newvc.mj_header endRefreshing]; } }]; newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf SystemmessageNetworkrequest:newvc.mj_footer]; }else{ [newvc.mj_footer endRefreshing]; } }]; } - (void)dismiss:(id)object { if ([object isKindOfClass:[MJRefreshNormalHeader class]]) { __weak UITableView *newvc = newtableView; [newvc.mj_header endRefreshing]; }else if ([object isKindOfClass:[MJRefreshBackNormalFooter class]]){ __weak UITableView *newvc = newtableView; [newvc.mj_footer endRefreshing]; }else { [MBProgressHUD hideHUDForView:self.view]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end