// // IfishUsersActivityListController.m // Ifish // // Created by imac on 2017/5/11. // Copyright © 2017年 lianlian. All rights reserved. // #import "IfishUsersActivityListController.h" #import "IFishUserActivityData.h" #import "IFishUserActivityListCell.h" #import "FishActivityData.h" #import "JHRefresh.h" #import "IfishUserDefaultHelper.h" const float ActivityPageSize = 20; @interface IfishUsersActivityListController () @property (nonatomic,strong) UITableView *tableView; @property (nonatomic,strong) NSMutableArray *dataArr; @property (nonatomic,strong) NSMutableArray *activTypes; @property (nonatomic) NSInteger firstResult; @property(nonatomic,copy) NSString* total; @property(nonatomic)BOOL isLoadMore; @property(nonatomic) int page; @end @implementation IfishUsersActivityListController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self addTitleViewWithTitle:@"实时动态"]; _dataArr =[[NSMutableArray alloc] init]; _page = 0; [self loadActypes]; [self creatTab]; [self requestListData]; [self creatReatRefreshView]; } -(void)loadActypes{ _activTypes = [[NSMutableArray alloc] init]; NSString *filePath = [[NSBundle mainBundle]pathForResource:@"ActivityData" ofType:@"json"]; NSData *data = [[NSData alloc]initWithContentsOfFile:filePath]; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSArray*typeListArr = [dic objectForKey:@"data"];; for (NSDictionary *typedict in typeListArr ) { FishActivityData *model = [[FishActivityData alloc] initWithDict:typedict]; [_activTypes addObject:model]; } } -(void)requestListData{ NSString *useriD= [dataContorl dataControlGetUserIdInfo]; NSInteger pageSize = ActivityPageSize ; _firstResult = 0; __weak typeof (self)weakSelf = self; [AFHttpTool getUserActivity:useriD pageSize:pageSize firstResult:_firstResult success:^(id response) { NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil]; if ([reDic[@"result"] isEqualToString:@"100"]){ _total = [reDic objectForKey:@"total"]; NSArray *daA =reDic[@"data"]; for (NSDictionary *dic in daA) { IFishUserActivityData *data = [[IFishUserActivityData alloc] initWithDict:dic]; [_dataArr addObject:data]; } //存储当前最大Id IFishUserActivityData *data = _dataArr[0]; [IfishUserDefaultHelper saveUserActivityMaxId:data.activityId]; [weakSelf.tableView reloadData]; }else{ [weakSelf.view makeToast:@"请求失败"]; } } failure:^(NSError *err) { [weakSelf.view makeToast:@"请求异常"]; }]; } -(void)creatTab{ self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.scrollEnabled = YES; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.showsVerticalScrollIndicator = NO; self.tableView.backgroundColor = RGB(242, 242, 242); [self.view addSubview:self.tableView]; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return self.dataArr.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ IFishUserActivityListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IFishUserActivityListCell"]; if (!cell) { cell = [[[NSBundle mainBundle]loadNibNamed:@"IFishUserActivityListCell" owner:self options:nil]lastObject]; } IFishUserActivityData *data = _dataArr[indexPath.section]; [cell loadDataWith:data typeArr:_activTypes]; return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 124; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ if (section==0) { return 0.01; }else{ return 10; } } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 0.01; } -(void)creatReatRefreshView{ __weak typeof (self)weskSelf=self; //上拉加载更多 [weskSelf.tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{ if (weskSelf.isLoadMore) { return ; } weskSelf.isLoadMore=YES; NSInteger pagecount =[_total integerValue]/ActivityPageSize + 1; if (_page