123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- //
- // StuExamsListVC.m
- // LN_School
- //
- // Created by EchoShacolee on 2017/6/16.
- // Copyright © 2017年 Danson. All rights reserved.
- //
- #import "StuExamsListVC.h"
- #import "MengBanView.h"
- #import "DateView.h"
- #import "MJRefresh.h"
- #import "StuExamListCell.h"
- typedef NS_ENUM(NSInteger, MyGetDataType) {
- //正常请求数据
- MyGetDataTypeNomal=0,
- //下拉刷新请求数据
- MyGetDataTypeHeaderRefresh,
- //上拉加载更多请求数据
- MyGetDataTypeFooterRefresh
- };
- @interface StuExamsListVC ()<UITableViewDataSource,UITableViewDelegate>
- {
- MengBanView * _mengBanView;
- //记录页书
- NSInteger _currentPageNum;
- //正在加载的状态
- BOOL _IS_LOADING;
- //加载数据的类型
- MyGetDataType _getDataType;
-
- //
- HolderView *_holderV;
- }
- @property (nonatomic,retain)NSMutableArray * dataurce;
- @property(nonatomic,retain)UITableView *tableView;
- @end
- @implementation StuExamsListVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title = @"预考成绩";
- self.view.backgroundColor = KBackGroundColor;
- self.navigationController.navigationBar.translucent = NO;
-
- _dataurce = [[NSMutableArray alloc]init];
- _currentPageNum = 0;
- _IS_LOADING = NO;
- _getDataType = MyGetDataTypeNomal;
-
-
- _tableView = [[UITableView alloc]initWithFrame:kFrame style:UITableViewStyleGrouped];
- _tableView.height -= kNavOffSet+kSafeAreaBottomHeight;
- _tableView.backgroundColor = KBackGroundColor;
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.tableFooterView = [UIView new];
- [self.view addSubview:_tableView];
-
- [self setRefreshAction];
- [self goBackFirstVCByNavigation];
- [self customRightBtn];
-
- [self getData];
-
- _holderV = [[HolderView alloc]initWithFrame:_tableView.frame];
- [_holderV freshBlock:^{
- [self headerRefresh];
- }];
- [self.view addSubview:_holderV];
-
-
-
- }
- -(void)customRightBtn{
-
- UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"条件搜索" style:UIBarButtonItemStylePlain target:self action:@selector(search)];
- item.tintColor = RQMianColor;
- self.navigationItem.rightBarButtonItem = item;
- }
- -(void)search{
-
- [self.navigationController popViewControllerAnimated:YES];
-
- }
- #pragma mark - 下拉刷新,上拉加载 -
- -(void)setRefreshAction{
-
- // 下拉刷新
- __weak typeof(self) weakSelf = self;
- MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- [weakSelf headerRefresh];
- }];
- _tableView.mj_header = mj_header;
-
- MJRefreshBackNormalFooter *mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
- [weakSelf footerRefresh];
- }];
- _tableView.mj_footer = mj_footer;
-
- }
- #pragma mark - 数据加载更多和刷新 -
- -(void)headerRefresh{
- //设置获取数据的方式
- _getDataType=MyGetDataTypeHeaderRefresh;
- //加载数据
- [self getData];
- [_tableView.mj_header endRefreshing];
- }
- -(void)footerRefresh{
- //设置获取数据的方式
- _getDataType=MyGetDataTypeFooterRefresh;
- //加载数据
- [self getData];
- [_tableView.mj_footer endRefreshing];
- }
- #pragma mark tableView代理方法
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
-
- return self.dataurce.count;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- StuExamListCell *cell = [StuExamListCell cellForTableView:tableView];
- cell.dic = _dataurce[indexPath.section];
-
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- return 110;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
-
- return 15;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
-
- return 0.1f;
- }
- #pragma mark 数据请求
- -(void)getData{
-
- //判断当前是否正在加载数据。如果正在加载数据,直接return。
- if (_IS_LOADING) {
- return;
- }
-
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- _IS_LOADING=YES;
- //获取第一页数据
- NSInteger needLoadPage;
- needLoadPage=_currentPageNum+1;
- if (_getDataType==MyGetDataTypeHeaderRefresh) {
- needLoadPage=1;
- }
-
-
- [self.requestDic setObject:@"1" forKey:@"isPage"];
- [self.requestDic setObject:@"10" forKey:@"pageSize"];
- [self.requestDic setObject:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"];
-
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSString* method = @"getStuExams";
- __weak typeof(self) weakSelf = self;
- [NetManager requestAnythingWithURL:method dictionary:self.requestDic dataArray:nil completion:^(NSDictionary *root) {
-
- _holderV.hidden = NO;
- //设置加载状态
- _IS_LOADING=NO;
-
- if (!root) {
- ShowErrorMsg(@"请求失败!");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowErrorMsg(root[@"msg"]);
- return;
- }
-
- //处理数据
- //如果获取到了数据,而且是下拉刷新,清空数组。
- if (_getDataType==MyGetDataTypeHeaderRefresh){
- [weakSelf.dataurce removeAllObjects];
- }
- //追加数据
- [weakSelf.dataurce addObjectsFromArray:root[@"body"]];
- if (weakSelf.dataurce.count != 0) {
- _holderV.hidden = YES;
- }
- //计数器+1
- _currentPageNum=needLoadPage;
- //刷新界面
- [weakSelf.tableView reloadData];
-
- //恢复初始状态。
- _getDataType=MyGetDataTypeNomal;
- }];
- }
- - (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
|