FaqVC.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //学车问答
  2. #import "FaqVC.h"
  3. #import "STButton.h"
  4. #import "PostQues.h"
  5. #import "FaqCell.h"
  6. #import "HolderView.h"
  7. @interface FaqVC ()<UITableViewDelegate,UITableViewDataSource>
  8. {
  9. UITableView *myTableView;
  10. HolderView *holdV;
  11. NSMutableArray *models;
  12. int currentPage;
  13. BOOL refreshing;
  14. }
  15. @end
  16. @implementation FaqVC
  17. - (void)viewDidLoad
  18. {
  19. [super viewDidLoad];
  20. [self myInit];
  21. }
  22. - (void)didReceiveMemoryWarning {
  23. [super didReceiveMemoryWarning];
  24. }
  25. #pragma mark -
  26. -(void)myInit
  27. {
  28. currentPage = 1;
  29. [self configNavigationBar];
  30. [self setTitle:@"学车问答"];
  31. self.navigationController.navigationBar.translucent = NO;
  32. [self.view setBackgroundColor:[UIColor whiteColor]];
  33. models = [NSMutableArray array];
  34. [self search];
  35. UITableView* tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height - kNavOffSet - 4) style:UITableViewStyleGrouped];
  36. tv.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, .1)];
  37. [self.view addSubview:tv];
  38. myTableView = tv;
  39. [myTableView setDelegate:self];
  40. [myTableView setDataSource:self];
  41. myTableView.estimatedSectionHeaderHeight = 0;
  42. myTableView.estimatedSectionFooterHeight = 0;
  43. holdV = [[HolderView alloc] initWithFrame:tv.frame];
  44. [holdV freshBlock:^{
  45. [self search];
  46. }];
  47. [self.view addSubview:holdV];
  48. [holdV setHidden:YES];
  49. CGFloat x,y,w,h;
  50. NSInteger tag = 0;
  51. h = 60;
  52. UIView* bar = [[UIView alloc] initWithFrame:CGRectMake(0, kSize.height - kNavOffSet-2 -h-kSafeAreaBottomHeight, kSize.width, h )];
  53. [bar setBackgroundColor:backGroundColor];
  54. [bar addSelfViewWithRect:CGRectMake(0, 0, kSize.width, 1) Color:KlineColor];
  55. [self.view addSubview:bar];
  56. y = 0;
  57. w = 100;
  58. x = (kSize.width - w)/2.0;
  59. STButton* stBtn = [[STButton alloc] initWithFrame:CGRectMake(x, y, w, h)];
  60. [stBtn setImage:[[UIImage imageNamed:@"community2.png"] tint:defGreen] withTitle:@"提问" Font:SmallFont forState:UIControlStateNormal];
  61. [stBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  62. [stBtn setStyle:1];
  63. [stBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  64. [bar addSubview:stBtn];
  65. [stBtn setTag:tag++];
  66. }
  67. -(void)btnClick:(UIButton*)sender
  68. {
  69. int tag = (int)sender.tag;
  70. if (0 == tag) {
  71. PostQues* vc = [PostQues new];
  72. [vc setJxbh:_jxbh];
  73. [vc preFreshBlock:^{
  74. [models removeAllObjects];
  75. currentPage = 1;
  76. [self search];
  77. }];
  78. [self navPushHideTabbarToVC:vc];
  79. }
  80. }
  81. #pragma mark -
  82. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  83. {
  84. if (0 == section) {
  85. return .1;
  86. }else{
  87. return 20;
  88. }
  89. }
  90. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  91. {
  92. return .1;
  93. }
  94. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  95. {
  96. return 1;
  97. }
  98. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  99. {
  100. return models.count;
  101. }
  102. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  103. {
  104. NSDictionary *dic = models[indexPath.section];
  105. CGFloat h1 = [dic[@"content"] heightForWid:kSize.width - 80 Font:14];
  106. if (h1 < 25) {
  107. h1 = 25;
  108. }
  109. CGFloat h2 = [dic[@"answerContent"] heightForWid:kSize.width - 80 Font:14];
  110. if (h2 < 25) {
  111. h2 = 25;
  112. }
  113. return h1 + h2 + 90;
  114. }
  115. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  116. {
  117. FaqCell* cell = [FaqCell cellForTableView:tableView];
  118. [cell setModel:models[indexPath.section]];
  119. cell.userInteractionEnabled = NO;
  120. return cell;
  121. }
  122. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  123. {
  124. // NSLog(@"scrollViewDidEndDecelerating refreshing %d",refreshing);
  125. if (refreshing) {
  126. return;
  127. }
  128. CGPoint off = scrollView.contentOffset;
  129. if (scrollView.contentSize.height - off.y - scrollView.frame.size.height < 1) {
  130. [scrollView setContentOffset:CGPointMake(off.x, off.y - 10) animated:YES];
  131. // NSLog(@"AT bottom");
  132. [self search];
  133. }
  134. }
  135. #pragma mark -
  136. -(void)search
  137. {
  138. refreshing = 1;
  139. [holdV setHidden:1];
  140. [self getAppQuestionsByJxbh];
  141. }
  142. -(void)getAppQuestionsByJxbh
  143. {
  144. [holdV setHidden:0];
  145. if (![Util connectedToNetWork]) {
  146. showMsgUnconnect();
  147. return;
  148. }
  149. NSMutableArray *arr=[NSMutableArray array];
  150. [arr addPro:@"jxbh" Value:_jxbh];
  151. [arr addPro:@"isPage" Value:@"1"];
  152. [arr addPro:@"pageSize" Value:@"10"];
  153. [arr addPro:@"currentPage" Value:[NSString stringWithFormat:@"%d",currentPage]];
  154. NSString* method = @"getAppQuestionsByJxbh";
  155. [MBProgressHUD showLoadToView:self.view];
  156. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  157. [MBProgressHUD hideHUDForView:self.view];
  158. refreshing = 0;
  159. //NSLog(@"驾校详情-->%@ 驾校问答数据---->%@",arr,root);
  160. if (!root)
  161. {
  162. ShowMsgFailed();
  163. return;
  164. }
  165. if ( 1 == [root[@"code"] intValue] ) {
  166. ShowMsgFailed();
  167. return;
  168. }
  169. NSArray* resArr = root[@"body"];
  170. if (resArr.count) {
  171. currentPage++;
  172. [models addObjectsFromArray:resArr];
  173. [myTableView reloadData];
  174. }else{
  175. ShowMsg(@"已加载全部");
  176. }
  177. [holdV setHidden:models.count];
  178. }];
  179. }
  180. @end