123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- //
- // HelpQuestionVC.m
- // jiaPei
- //
- // Created by apple on 16/8/16.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "HelpQuestionVC.h"
- #import "HelpHeaderView.h"
- @interface HelpQuestionVC ()<UITableViewDataSource,UITableViewDelegate>
- {
- UITableView *mainTableView;
- NSArray *modelsArray;
- BOOL isopen[100];
- NSInteger lastOne;
- }
- @end
- @implementation HelpQuestionVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = backGroundColor;
-
- // if ([self.source isEqualToString:@"left"]) {
- // [self configNavigationBarDismissNav];
- // }else{
- // }
- [self configNavigationBar];
-
-
- [self myInit];
- }
- -(void)myInit
- {
- modelsArray = [NSArray array];
-
- mainTableView = [[UITableView alloc] initWithFrame:kFrame];
- mainTableView.height -= kNavOffSet;
- mainTableView.delegate = self;
- mainTableView.dataSource = self;
- mainTableView.estimatedSectionFooterHeight = 0;
- [self.view addSubview:mainTableView];
-
- [self getAppQuestion];
- }
- #pragma mark tableView delegate
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return modelsArray.count;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (isopen[section] == YES)
- {
- NSArray *array = [NSArray array];
- if ([modelsArray[section] isKindOfClass:[NSDictionary class]]){
- array = [modelsArray[section] objectForKey:@"questions"];
- }
- return array.count;
- }else{
- return 0;
- }
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
- }
-
- NSArray *array = [NSArray array];
- if ([modelsArray[indexPath.section] isKindOfClass:[NSDictionary class]]){
- array = [modelsArray[indexPath.section] objectForKey:@"questions"];
- }
-
- NSDictionary *dic = array[indexPath.row];
- NSString *tit = dic[@"SQ_TITLE"];
- NSString *answer = dic[@"SQ_ANSWER"];
- answer = [answer stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
- answer = [answer stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
-
- [cell.textLabel setText:[NSString stringWithFormat:@"%d、%@",(int)indexPath.row + 1,tit] Font:Font17 TextColor:[UIColor orangeColor]];
- cell.textLabel.numberOfLines = 0;
-
- [cell.detailTextLabel setText:[NSString stringWithFormat:@"答:%@",answer] Font:NormalFont TextColor:contentTextColor];
- cell.detailTextLabel.numberOfLines = 0;
-
- return cell;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSArray *array = [NSArray array];
- if ([modelsArray[indexPath.section] isKindOfClass:[NSDictionary class]]){
- array = [modelsArray[indexPath.section] objectForKey:@"questions"];
- }
- NSDictionary *dic = array[indexPath.row];
-
- NSString *tit = dic[@"SQ_TITLE"];
- NSString *answer = dic[@"SQ_ANSWER"];
- answer = [answer stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
-
- CGFloat titleHei = [tit heightForWid:kSize.width - 20 Font:Font17];
- CGFloat answerHei = [answer heightForWid:kSize.width - 20 Font:NormalFont];
-
- return titleHei + answerHei + 40;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- HelpHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
- if (headerView == nil) {
-
- headerView = [[HelpHeaderView alloc] initWithReuseIdentifier:@"header"];
- }
-
- //设置区头名字
- if ([modelsArray[section] isKindOfClass:[NSDictionary class]]){
- headerView.titleLabel.text = [modelsArray[section] objectForKey:@"SQT_TITLE"];
- }
-
- headerView.transformImg.transform = isopen[section] == YES?CGAffineTransformMakeRotation(M_PI):CGAffineTransformIdentity;
-
- headerView.transformBtn.tag = section;
- [headerView.transformBtn addTarget:self action:@selector(clickToChange:) forControlEvents:UIControlEventTouchUpInside];
-
- return headerView;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 50;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return .1;
- }
- -(void)clickToChange:(UIButton *)sender
- {
- isopen[sender.tag] = !isopen[sender.tag];
-
- NSInteger whichOne = sender.tag;
-
- if (lastOne != whichOne)
- {
- isopen[lastOne] = NO;
- }
-
- lastOne = whichOne;
-
- [mainTableView reloadData];
- }
- #pragma mark 数据请求
- -(void)getAppQuestion
- {
- if (![Util connectedToNetWork]) {
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addPro:@"type" Value:@"3"];
-
- NSString* method = @"getAppQuestion";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
-
- [MBProgressHUD hideHUDForView:self.view];
-
- if (!root || [root[@"code"] intValue] == 1)
- {
- return;
- }
- if ([root[@"body"] count] < 1)
- {
- return;
- }
- modelsArray = root[@"body"];
- [mainTableView reloadData];
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|