// // MinRescord.m // LNManager // // Created by EchoShacolee on 2017/4/14. // Copyright © 2017年 lee. All rights reserved. // #import "MinRescord.h" #import "MinRecordeCell.h" @interface MinRescord () { // UIButton *trainbtn; // UIButton *photoBtn; // // UIView *photoView; //记录页书 NSInteger _currentPageNum; //加载数据的类型 MyGetDataType _getDataType; } @end @implementation MinRescord - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"电子日志详细"; // self.automaticallyAdjustsScrollViewInsets = NO; // UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, kNavOffSet + 10, kSize.width/2.0 - 30, 40)]; // [btn setTitle:@"分钟学时" textColor:COLOR_THEME font:FontTitle fotState:UIControlStateNormal]; // [btn borderColor:COLOR_THEME width:1 cornorRadios:3]; // [btn addTarget:self action:@selector(trainAction) forControlEvents:UIControlEventTouchUpInside]; // [self.view addSubview:btn]; // trainbtn = btn; // // btn = [[UIButton alloc] initWithFrame:CGRectMake(kSize.width/2.0 + 10, kNavOffSet + 10, kSize.width/2.0 - 30, 40)]; // [btn setTitle:@"训练照片" textColor:RGB_COLOR(136,136,136) font:FontTitle fotState:UIControlStateNormal]; // [btn borderColor:RGB_COLOR(136,136,136) width:1 cornorRadios:3]; // [btn addTarget:self action:@selector(photoAction) forControlEvents:UIControlEventTouchUpInside]; // [self.view addSubview:btn]; // photoBtn = btn; // // UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(10, kNavOffSet + 60, kSize.width - 20, 1)]; // line.backgroundColor = RGB_COLOR(136,136,136); // [self.view addSubview:line]; // // self.tableView.y = kNavOffSet + 61; // self.tableView.height = kSize.height - kNavOffSet - 61; // // //添加一个图片轮播器在这里 设置在屏幕右边 // photoView = [[UIView alloc] initWithFrame:self.tableView.frame]; // photoView.x = kSize.width; // photoView.backgroundColor = [UIColor redColor]; // [self.view addSubview:photoView]; [self getData]; [self setRefreshAction]; //点击刷新的回调 __weak typeof(self) weakSelf = self; self.block = ^{ _currentPageNum = 0; [weakSelf headerRefresh]; }; } //- (void)trainAction { // [trainbtn setTitleColor:COLOR_THEME forState:UIControlStateNormal]; // trainbtn.layer.borderColor = COLOR_THEME.CGColor; // // [photoBtn setTitleColor:RGB_COLOR(136,136,136) forState:UIControlStateNormal]; // photoBtn.layer.borderColor = RGB_COLOR(136, 136, 136).CGColor; // if (self.tableView.x != 0) { // [UIView animateWithDuration:.4 animations:^{ // self.tableView.x = 0; // photoView.x = kSize.width; // }]; // } //} // //- (void)photoAction { // [trainbtn setTitleColor:RGB_COLOR(136,136,136) forState:UIControlStateNormal]; // trainbtn.layer.borderColor = RGB_COLOR(136, 136, 136).CGColor; // // [photoBtn setTitleColor:COLOR_THEME forState:UIControlStateNormal]; // photoBtn.layer.borderColor = COLOR_THEME.CGColor; // if (photoView.x != 0) { // [UIView animateWithDuration:.4 animations:^{ // self.tableView.x = -kSize.width; // photoView.x = 0; // }]; // } //} #pragma mark tableview代理相关 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataurce.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 100; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ MinRecordeCell * cell = [tableView dequeueReusableCellWithIdentifier:@"minRecordCellId"]; if (!cell) { cell = [[[NSBundle mainBundle] loadNibNamed:@"MinRecordeCell" owner:nil options:nil] lastObject]; } [cell upDataWithDic:self.dataurce[indexPath.row]]; return cell; } #pragma mark - 下拉刷新,上拉加载 - -(void)setRefreshAction{ // 下拉加载更多 __weak typeof(self) weakSelf = self; MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ [weakSelf headerRefresh]; }]; self.tableView.mj_header = header; MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ [weakSelf footerRefresh]; }]; self.tableView.mj_footer = footer; } -(void)headerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeHeaderRefresh; //加载数据 [self getData]; [self.tableView.mj_header endRefreshing]; } -(void)footerRefresh{ //设置获取数据的方式 _getDataType=MyGetDataTypeFooterRefresh; //加载数据 [self getData]; [self.tableView.mj_footer endRefreshing]; } -(void)getData{ //判断当前是否正在加载数据。如果正在加载数据,直接return。 if (_IS_LOADING) { return; } _IS_LOADING=YES; //获取第一页数据 NSInteger needLoadPage; needLoadPage=_currentPageNum+1; if (_getDataType==MyGetDataTypeHeaderRefresh) { needLoadPage=1; } NSMutableDictionary *mdic = [[NSMutableDictionary alloc]init]; [mdic setValue:self.stuDic[@"STUNUM"] forKey:@"stunum"]; [mdic setValue:self.stuDic[@"CLASSID"] forKey:@"classId"]; [mdic setValue:@"1" forKey:@"isPage"]; [mdic setValue:@"10" forKey:@"pageSize"]; [mdic setValue:[NSString stringWithFormat:@"%ld",(long)needLoadPage] forKey:@"currentPage"]; __weak typeof(self) weakSelf = self; [self getDataWithDic:mdic method:@"trainTimesRecordMins" block:^(NSDictionary *successDic) { //处理数据 //如果获取到了数据,而且是下拉刷新,清空数组。 if (_getDataType==MyGetDataTypeHeaderRefresh){ [weakSelf.dataurce removeAllObjects]; } //追加数据 [weakSelf.dataurce addObjectsFromArray:successDic[@"body"]]; if (weakSelf.dataurce.count != 0) { weakSelf.holderV.hidden = YES; } if ([successDic[@"body"] count] != 0) { //计数器+1 _currentPageNum=needLoadPage; } //刷新界面 [weakSelf.tableView reloadData]; //恢复初始状态。 _getDataType=MyGetDataTypeNomal; }]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end