| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- //
- // NewFenLeiViewController.m
- // jitao
- //
- // Created by 罗云飞 on 2018/8/31.
- // Copyright © 2018年 罗云飞. All rights reserved.
- //
- #import "NewFenLeiViewController.h"
- //#import "FLZLCell.h"
- //#import "FLZLTableViewCell.h"
- #import "NewFWXMViewController.h"
- @interface NewFenLeiViewController ()<UITableViewDataSource,UITableViewDelegate>{
- UITableView *newtableView;
- UITableView *newtableView1;
- NSMutableArray *dataArr1;
- NSMutableArray *dataArr2;
- NSMutableArray *dataArr3;
- NSMutableArray *dataArr;
- NSMutableArray *nameArr;
- NSMutableArray *nameArr1;
- NSMutableArray *isOpenArr;
- NSMutableArray *SelectArr;
-
- }
- @end
- @implementation NewFenLeiViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavTitle:@"科技项目分类"];
- [self loaddata];
- [self networkRequest];
- [self loadUI];
- // Do any additional setup after loading the view.
- }
- - (void)loaddata{
- dataArr1 = NewMutableArrayInit;
- dataArr2 = NewMutableArrayInit;
- dataArr3 = NewMutableArrayInit;
- isOpenArr = NewMutableArrayInit;
- SelectArr = NewMutableArrayInit;
- dataArr = NewMutableArrayInit;
- nameArr = NewMutableArrayInit;
- nameArr1 = NewMutableArrayInit;
-
- }
- - (void)networkRequest
- {
- NSMutableDictionary *parameters = NewMutableDictionaryInit;
-
- [NetworkRequestManager requestGetWithInterfacePrefix:JT_NewcategoryList parameters:parameters onSuccess:^(id requestData) {
- if ([requestData[@"error"] count] !=0) {
- for (NSDictionary *dic in requestData[@"error"]) {
- [MBProgressHUD showError:dic[@"message"] toView:self.view];
- }
- }else{
- [dataArr3 removeAllObjects];
- NSMutableArray *arr = [NSMutableArray arrayWithArray:requestData[@"data"]];
- dataArr3 = [NSMutableArray arrayWithArray:requestData[@"data"]];
- for (int i = 0; i<arr.count; i++) {
- [nameArr addObject:arr[i][@"name"]];
- }
- for (int i = 0; i<arr.count; i++) {
- if (i == self.page) {
- NSMutableArray *zibiaoti = [NSMutableArray arrayWithArray:arr[i][@"list"]];
- for (int j = 0; j<zibiaoti.count; j++) {
- [nameArr1 addObject:zibiaoti[j][@"topLevel"]];
- [dataArr addObject:zibiaoti[j][@"children"]];
- }
- }
- }
- for (int i = 0; i<dataArr.count; i++) {
- NSString *state = @"open";
- [isOpenArr addObject:state];
- }
- for (int i = 0; i<nameArr.count; i++) {
- if (i == self.page) {
- NSString *state=@"open";
- [SelectArr addObject:state];
- }else{
- NSString *state=@"close";
- [SelectArr addObject:state];
- }
- }
- [newtableView reloadData];
- [newtableView1 reloadData];
- }
- } onFailure:^{
-
- }];
- }
- #pragma mark----刷新子数据
- - (void)shuaxinTableViewData:(NSInteger)str{
- [nameArr1 removeAllObjects];
- [dataArr removeAllObjects];
- [isOpenArr removeAllObjects];
- [SelectArr removeAllObjects];
- for (int i = 0; i<dataArr3.count; i++) {
- if (i == str) {
- NSMutableArray *zibiaoti = [NSMutableArray arrayWithArray:dataArr3[i][@"list"]];
- for (int j = 0; j<zibiaoti.count; j++) {
- [nameArr1 addObject:zibiaoti[j][@"topLevel"]];
- [dataArr addObject:zibiaoti[j][@"children"]];
- }
- }
- }
- for (int i = 0; i<dataArr.count; i++) {
- NSString* state=@"close";
- [isOpenArr addObject:state];
- }
- for (int i = 0; i<nameArr.count; i++) {
- if (i == str) {
- NSString *state=@"open";
- [SelectArr addObject:state];
- }else{
- NSString *state=@"close";
- [SelectArr addObject:state];
- }
- }
- [newtableView reloadData];
- [newtableView1 reloadData];
- }
- -(void)loadUI
- {
- [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH/3, SCREEN_HEIGHT-NavHeader) backgroundColor:[UIColor colorWithString:@"#F5F5F5"] style:UITableViewStylePlain delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
- newtableView.separatorStyle = NO;
-
- [self.view addSubview:newtableView1 = [NewControlPackage tableViewInitWithFrame:CGRectMake(SCREEN_WIDTH/3, NavHeader, SCREEN_WIDTH*2/3, SCREEN_HEIGHT-NavHeader) backgroundColor:NewWhiteColor style:UITableViewStylePlain delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:101 userInteractionEnabled:YES]];
- newtableView1.separatorStyle = YES;
-
- // [_collect registerClass:[HRloveCollectionViewCell class] forCellWithReuseIdentifier:@"collectcell"];
-
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // return self.dataDict.allKeys.count;
- if (tableView.tag == 100) {
- return 1;
- }else{
- return dataArr.count;
- }
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (tableView.tag == 100) {
- return nameArr.count;
- }else if(tableView.tag == 101){
- NSString* state=[isOpenArr objectAtIndex:section];
- if ([state isEqualToString:@"open"]) {
- NSArray* arr=[dataArr objectAtIndex:section];
- return arr.count;
- }
- }
- return 0;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView.tag == 100) {
- static NSString *Cell = @"Cell";
- UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil) {
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryNone;
-
- // if ([SelectArr[indexPath.row] isEqualToString:@"open"]) {
- // cell.title.textColor = NewButtonColor;
- // cell.backgroundColor = NewWhiteColor;
- // cell.line.hidden = NO;
- // }else{
- // cell.title.textColor = NewBlackColor;
- // cell.backgroundColor = [UIColor colorWithString:@"#F5F5F5"];
- // cell.line.hidden = YES;
- // }
- // cell.title.text = nameArr[indexPath.row];
- return cell;
- }else{
- static NSString *Cell = @"Cell";
- UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
- if (cell == nil) {
- cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
- }
- [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
- cell.accessoryType = UITableViewCellAccessoryNone;
- // NSArray* sectionArr=[dataArr objectAtIndex:indexPath.section];
- // cell.title.text = sectionArr[indexPath.row][@"name"];
- return cell;
- }
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView.tag == 100) {
- [SelectArr removeAllObjects];
- for (int i = 0; i<nameArr.count; i++) {
- if (indexPath.row == i) {
- NSString *state=@"open";
- [SelectArr addObject:state];
- }else{
- NSString *state=@"close";
- [SelectArr addObject:state];
- }
- }
- [self shuaxinTableViewData:indexPath.row];
- [newtableView reloadData];
- }else{
- for (int i = 0; i<SelectArr.count; i++) {
- if ([SelectArr[i] isEqualToString:@"open"]) {
- NSLog(@"%@",dataArr3[i][@"list"][indexPath.section][@"topLevelId"]);
- NSMutableArray *arr = dataArr3[i][@"list"][indexPath.section][@"children"];
- NSLog(@"%@",arr[indexPath.row][@"id"]);
- NewFWXMViewController *vc = [[NewFWXMViewController alloc] init];
- vc.topId = dataArr3[i][@"list"][indexPath.section][@"topLevelId"];
- vc.secondId = arr[indexPath.row][@"id"];
- NewPushViewController(vc);
- }
- }
- }
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if (tableView.tag == 100) {
- return 55;
- }else{
- return 55;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- if (tableView.tag == 100) {
- return CGFLOAT_MIN;
- }else{
- return 55;
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- if (tableView.tag == 100) {
- return [[UIView alloc] init];
- }else{
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/3, 55)];
- UILabel *title = [UILabel new];
- if (nameArr1.count>0) {
- title.text = nameArr1[section];
- }
- title.font = NewFont(14);
- title.textColor = NewButtonColor;
- [title setSingleLineAutoResizeWithMaxWidth:0];
- [view addSubview:title];
-
- title.sd_layout
- .leftSpaceToView(view, 20)
- .heightIs(55)
- .topEqualToView(view);
-
- UIImageView* stateImage=[[UIImageView alloc] init];
- if (isOpenArr.count>0) {
- if ([[isOpenArr objectAtIndex:section] isEqualToString:@"open"]) {
- [stateImage setImage:[UIImage imageNamed:@"sectionOpen"]];
- }
- else if ([[isOpenArr objectAtIndex:section] isEqualToString:@"close"]) {
- [stateImage setImage:[UIImage imageNamed:@"sectionClose"]];
- }
- }else{
- [stateImage setImage:[UIImage imageNamed:@"sectionClose"]];
- }
- [view addSubview:stateImage];
-
- stateImage.sd_layout
- .rightSpaceToView(view, 15)
- .heightIs(7)
- .widthIs(13)
- .centerYEqualToView(view);
-
- UIButton *button = [UIButton new];
- NewTouchUpInside(button, buttonclick:);
- button.tag = 100+section;
- [view addSubview:button];
-
- button.sd_layout
- .leftEqualToView(view)
- .rightEqualToView(view)
- .topEqualToView(view)
- .bottomEqualToView(view);
-
- UILabel *line = [UILabel new];
- line.backgroundColor = NewLineGrayColor;
- [view addSubview:line];
-
- line.sd_layout
- .leftEqualToView(view)
- .rightEqualToView(view)
- .heightIs(1)
- .bottomEqualToView(view);
- return view;
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
- return [[UIView alloc] init];
- }
- - (void)buttonclick:(UIButton *)sender {
- NSString* state=[isOpenArr objectAtIndex:sender.tag-100];
- if ([state isEqualToString:@"open"]) {
- state=@"close";
- }else
- {
- state=@"open";
- }
- isOpenArr[sender.tag-100]=state;
- NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:sender.tag-100];
- [newtableView1 reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
-
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|