// // MyneedsViewController.m // jitao // // Created by 罗云飞 on 2017/12/8. // Copyright © 2017年 罗云飞. All rights reserved. // #import "MyneedsViewController.h" #import "MyneedsCell.h" #import "MyneedsModel.h" #import "DemanddetailViewController.h" @interface MyneedsViewController (){ UITableView *newtableView; NSMutableArray *dataArray; int pageNo; } @end @implementation MyneedsViewController - (void)viewDidLoad { [super viewDidLoad]; [self setNavTitle:@"我的需求"]; [self dataInitialization]; [self myneedsNetworkrequest:nil]; [self loadsView]; [self addRefreshing]; // Do any additional setup after loading the view. } #pragma mark -----我的需求列表网络请求------ - (void)myneedsNetworkrequest:(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"];//页面显示数 [NetworkRequestManager requestGetWithInterfacePrefix:JT_MydemandList 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"]) { MyneedsModel *model = [[MyneedsModel alloc] initWithDictionary:dic error:nil]; [dataArray addObject:model]; } //查询不到类型底图 if (dataArray.count<=0) { [self addErrorLoadingFrame:CGRectMake(0, ViewStartY, 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, ViewStartY, SCREEN_WIDTH, SCREEN_HEIGHT-ViewStartY) 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 3; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *Cell = @"Cell"; MyneedsCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell]; if (cell == nil) { cell = [[MyneedsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果) cell.accessoryType = UITableViewCellAccessoryNone; if (dataArray.count>0) { [cell assignment:dataArray[indexPath.row]]; } return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return fitScreenWidth(142); } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ MyneedsModel *model = dataArray[indexPath.row]; DemanddetailViewController *vc = [[DemanddetailViewController alloc] init]; vc.ID = model.ID; NewPushViewController(vc); } - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return CGFLOAT_MIN; } - (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 myneedsNetworkrequest:newvc.mj_header]; }else{ [newvc.mj_header endRefreshing]; } }]; newvc.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ if ([NetworkRequestManager connectedToNetwork]) { [weakSelf myneedsNetworkrequest: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