//学车问答 #import "FaqVC.h" #import "STButton.h" #import "PostQues.h" #import "FaqCell.h" #import "HolderView.h" @interface FaqVC () { UITableView *myTableView; HolderView *holdV; NSMutableArray *models; int currentPage; BOOL refreshing; } @end @implementation FaqVC - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - -(void)myInit { currentPage = 1; [self configNavigationBar]; [self setTitle:@"学车问答"]; self.navigationController.navigationBar.translucent = NO; [self.view setBackgroundColor:[UIColor whiteColor]]; models = [NSMutableArray array]; [self search]; UITableView* tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height - kNavOffSet - 4) style:UITableViewStyleGrouped]; tv.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, .1)]; [self.view addSubview:tv]; myTableView = tv; [myTableView setDelegate:self]; [myTableView setDataSource:self]; myTableView.estimatedSectionHeaderHeight = 0; myTableView.estimatedSectionFooterHeight = 0; holdV = [[HolderView alloc] initWithFrame:tv.frame]; [holdV freshBlock:^{ [self search]; }]; [self.view addSubview:holdV]; [holdV setHidden:YES]; CGFloat x,y,w,h; NSInteger tag = 0; h = 60; UIView* bar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - kNavOffSet-2 -h-kSafeAreaBottomHeight, kSize.width, h )]; [bar setBackgroundColor:backGroundColor]; [bar addSelfViewWithRect:CGRectMake(0, 0, kSize.width, 1) Color:KlineColor]; [self.view addSubview:bar]; y = 0; w = 100; x = (kSize.width - w)/2.0; STButton* stBtn = [[STButton alloc] initWithFrame:CGRectMake(x, y, w, h)]; [stBtn setImage:[[UIImage imageNamed:@"community2.png"] tint:defGreen] withTitle:@"提问" Font:SmallFont forState:UIControlStateNormal]; [stBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [stBtn setStyle:1]; [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal]; [bar addSubview:stBtn]; [stBtn setTag:tag++]; } -(void)btnClick:(UIButton*)sender { int tag = (int)sender.tag; if (0 == tag) { PostQues* vc = [PostQues new]; [vc setJxbh:_jxbh]; [vc preFreshBlock:^{ [models removeAllObjects]; currentPage = 1; [self search]; }]; [self navPushHideTabbarToVC:vc]; } } #pragma mark - -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (0 == section) { return .1; }else{ return 20; } } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return .1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return models.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dic = models[indexPath.section]; CGFloat h1 = [dic[@"content"] heightForWid:kSize.width - 80 Font:14]; if (h1 < 25) { h1 = 25; } CGFloat h2 = [dic[@"answerContent"] heightForWid:kSize.width - 80 Font:14]; if (h2 < 25) { h2 = 25; } return h1 + h2 + 90; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { FaqCell* cell = [FaqCell cellForTableView:tableView]; [cell setModel:models[indexPath.section]]; cell.userInteractionEnabled = NO; return cell; } -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { // NSLog(@"scrollViewDidEndDecelerating refreshing %d",refreshing); if (refreshing) { return; } CGPoint off = scrollView.contentOffset; if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) { [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES]; // NSLog(@"AT bottom"); [self search]; } } #pragma mark - -(void)search { refreshing = 1; [holdV setHidden:1]; [self getAppQuestionsByJxbh]; } -(void)getAppQuestionsByJxbh { [holdV setHidden:0]; if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"jxbh" Value:_jxbh]; [arr addPro:@"isPage" Value:@"1"]; [arr addPro:@"pageSize" Value:@"10"]; [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage]]; NSString* method = @"getAppQuestionsByJxbh"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { [MBProgressHUD hideHUDForView:self.view]; refreshing = 0; //NSLog(@"驾校详情-->%@ 驾校问答数据---->%@",arr,root); if (!root) { ShowMsgFailed(); return; } if ( 1 == [root[@"code"] intValue] ) { ShowMsgFailed(); return; } NSArray* resArr = root[@"body"]; if (resArr.count) { currentPage++; [models addObjectsFromArray:resArr]; [myTableView reloadData]; }else{ ShowMsg(@"已加载全部"); } [holdV setHidden:models.count]; }]; } @end