HelpQuestionVC.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //
  2. // HelpQuestionVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/8/16.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "HelpQuestionVC.h"
  9. #import "HelpHeaderView.h"
  10. @interface HelpQuestionVC ()<UITableViewDataSource,UITableViewDelegate>
  11. {
  12. UITableView *mainTableView;
  13. NSArray *modelsArray;
  14. BOOL isopen[100];
  15. NSInteger lastOne;
  16. }
  17. @end
  18. @implementation HelpQuestionVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.view.backgroundColor = backGroundColor;
  22. // if ([self.source isEqualToString:@"left"]) {
  23. // [self configNavigationBarDismissNav];
  24. // }else{
  25. // }
  26. [self configNavigationBar];
  27. [self myInit];
  28. }
  29. -(void)myInit
  30. {
  31. modelsArray = [NSArray array];
  32. mainTableView = [[UITableView alloc] initWithFrame:kFrame];
  33. mainTableView.height -= kNavOffSet;
  34. mainTableView.delegate = self;
  35. mainTableView.dataSource = self;
  36. mainTableView.estimatedSectionFooterHeight = 0;
  37. [self.view addSubview:mainTableView];
  38. [self getAppQuestion];
  39. }
  40. #pragma mark tableView delegate
  41. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  42. {
  43. return modelsArray.count;
  44. }
  45. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  46. {
  47. if (isopen[section] == YES)
  48. {
  49. NSArray *array = [NSArray array];
  50. if ([modelsArray[section] isKindOfClass:[NSDictionary class]]){
  51. array = [modelsArray[section] objectForKey:@"questions"];
  52. }
  53. return array.count;
  54. }else{
  55. return 0;
  56. }
  57. }
  58. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  59. {
  60. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  61. if (cell == nil)
  62. {
  63. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  64. }
  65. NSArray *array = [NSArray array];
  66. if ([modelsArray[indexPath.section] isKindOfClass:[NSDictionary class]]){
  67. array = [modelsArray[indexPath.section] objectForKey:@"questions"];
  68. }
  69. NSDictionary *dic = array[indexPath.row];
  70. NSString *tit = dic[@"SQ_TITLE"];
  71. NSString *answer = dic[@"SQ_ANSWER"];
  72. answer = [answer stringByReplacingOccurrencesOfString:@"&lt;br>" withString:@"\n"];
  73. answer = [answer stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
  74. [cell.textLabel setText:[NSString stringWithFormat:@"%d、%@",(int)indexPath.row + 1,tit] Font:Font17 TextColor:[UIColor orangeColor]];
  75. cell.textLabel.numberOfLines = 0;
  76. [cell.detailTextLabel setText:[NSString stringWithFormat:@"答:%@",answer] Font:NormalFont TextColor:contentTextColor];
  77. cell.detailTextLabel.numberOfLines = 0;
  78. return cell;
  79. }
  80. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  81. {
  82. NSArray *array = [NSArray array];
  83. if ([modelsArray[indexPath.section] isKindOfClass:[NSDictionary class]]){
  84. array = [modelsArray[indexPath.section] objectForKey:@"questions"];
  85. }
  86. NSDictionary *dic = array[indexPath.row];
  87. NSString *tit = dic[@"SQ_TITLE"];
  88. NSString *answer = dic[@"SQ_ANSWER"];
  89. answer = [answer stringByReplacingOccurrencesOfString:@"&lt;br>" withString:@"\n"];
  90. CGFloat titleHei = [tit heightForWid:kSize.width - 20 Font:Font17];
  91. CGFloat answerHei = [answer heightForWid:kSize.width - 20 Font:NormalFont];
  92. return titleHei + answerHei + 40;
  93. }
  94. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  95. {
  96. HelpHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
  97. if (headerView == nil) {
  98. headerView = [[HelpHeaderView alloc] initWithReuseIdentifier:@"header"];
  99. }
  100. //设置区头名字
  101. if ([modelsArray[section] isKindOfClass:[NSDictionary class]]){
  102. headerView.titleLabel.text = [modelsArray[section] objectForKey:@"SQT_TITLE"];
  103. }
  104. headerView.transformImg.transform = isopen[section] == YES?CGAffineTransformMakeRotation(M_PI):CGAffineTransformIdentity;
  105. headerView.transformBtn.tag = section;
  106. [headerView.transformBtn addTarget:self action:@selector(clickToChange:) forControlEvents:UIControlEventTouchUpInside];
  107. return headerView;
  108. }
  109. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  110. {
  111. return 50;
  112. }
  113. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  114. {
  115. return .1;
  116. }
  117. -(void)clickToChange:(UIButton *)sender
  118. {
  119. isopen[sender.tag] = !isopen[sender.tag];
  120. NSInteger whichOne = sender.tag;
  121. if (lastOne != whichOne)
  122. {
  123. isopen[lastOne] = NO;
  124. }
  125. lastOne = whichOne;
  126. [mainTableView reloadData];
  127. }
  128. #pragma mark 数据请求
  129. -(void)getAppQuestion
  130. {
  131. if (![Util connectedToNetWork]) {
  132. return;
  133. }
  134. NSMutableArray *arr=[NSMutableArray array];
  135. [arr addPro:@"type" Value:@"3"];
  136. NSString* method = @"getAppQuestion";
  137. [MBProgressHUD showLoadToView:self.view];
  138. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  139. [MBProgressHUD hideHUDForView:self.view];
  140. if (!root || [root[@"code"] intValue] == 1)
  141. {
  142. return;
  143. }
  144. if ([root[@"body"] count] < 1)
  145. {
  146. return;
  147. }
  148. modelsArray = root[@"body"];
  149. [mainTableView reloadData];
  150. }];
  151. }
  152. - (void)didReceiveMemoryWarning {
  153. [super didReceiveMemoryWarning];
  154. }
  155. @end