CNLiveSearchViewController.m 54.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
//
//  CNLiveSearchViewController.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/26.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "CNLiveSearchViewController.h"
#import "VideoTableViewCell.h"
#import "ArticleTableViewCell.h"
#import "NoticeTableViewCell.h"
#import "SearchHistoryTableViewCell.h"
#import "CNHomeModel.h"

@interface CNLiveSearchViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>{
    UIView *backView;
    UIView *screenInterfaceView;
    UIView *hearderView;
    NSString *searchKey;
    NSString *searchTime;
    NSString *searchCategory;
    BOOL isShowResult;
    BOOL isShowScreenInterface;
    BOOL isTimeSelected;
    BOOL isCategorySelected;
    
    NSInteger timeIndex;
    NSInteger categoryIndex;
    NSInteger pageNumber;
    NSString *searchCategoryId;
}
@property (strong, nonatomic) UIButton *searchButton;
@property (strong, nonatomic) UITextField *textField;
@property (strong, nonatomic) UILabel *errorLabe;
@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) UITableView *screenTableView;
@property (strong, nonatomic) UIView *screenBackView;
@property (strong, nonatomic) UIButton *closeButton;
@property (strong, nonatomic) UIButton *reSetButton;
@property (strong, nonatomic) UIButton *doneButton;
@property (strong, nonatomic) NSMutableArray *historyArray;
@property (strong, nonatomic) NSMutableArray *resultArray;
@property (strong, nonatomic) NSMutableArray *screenArray;

@end
@implementation CNLiveSearchViewController
- (void)Pop:(id)sender{
    [self dismissViewControllerAnimated:NO completion:nil];
}
- (void)showScreenInterfaceView:(id)sender {
    isShowScreenInterface = !isShowScreenInterface;
    [UIView animateWithDuration:0.3 animations:^{
        if (!isShowScreenInterface) {
            self.screenBackView.frame = CGRectMake(MainScreenWidth, 0, MainScreenWidth, MainScreenHeight - NavBarHeight);
            self.screenTableView.frame = CGRectMake(MainScreenWidth, 0, MainScreenWidth - 40, MainScreenHeight - NavBarHeight);
            self.closeButton.frame = CGRectZero;
            self.reSetButton.frame = CGRectMake(MainScreenWidth, MainScreenHeight - 40- NavBarHeight, (MainScreenWidth - 40)/2, 40);
            self.doneButton.frame = CGRectMake(MainScreenWidth + (MainScreenWidth - 40)/2, MainScreenHeight - 40 - NavBarHeight, (MainScreenWidth - 40)/2, 40);
            
        } else {
            self.screenBackView.frame = CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - NavBarHeight);
            self.screenTableView.frame = CGRectMake(40, 0, MainScreenWidth - 40, MainScreenHeight - NavBarHeight);
            
            self.closeButton.frame = CGRectMake(0, 0, 40, MainScreenHeight - 20);
            
            self.reSetButton.frame = CGRectMake(40, MainScreenHeight - 40 - NavBarHeight, (MainScreenWidth - 40)/2, 40);
            self.doneButton.frame = CGRectMake(40 + (MainScreenWidth - 40)/2, MainScreenHeight - 40 - NavBarHeight, (MainScreenWidth - 40)/2, 40);
        }
    } completion:nil];
}
#pragma mark - UI
- (void)setUpNavigationBar{
    [self.navigationController setNavigationBarHidden:NO];

    self.navigationController.navigationBar.barTintColor = Color_Blue;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    UIButton *headerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
    headerButton.layer.cornerRadius = 2.0;
    headerButton.layer.masksToBounds = true;
    [headerButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal];
    [headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];
    
    self.navigationItem.title = @"搜索";
    
    //右
    UIButton *moreButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 21, 44)];
    [moreButton setImage:[UIImage imageNamed:@"cnlive_screen_inter"] forState:UIControlStateNormal];
    [moreButton addTarget:self action:@selector(showScreenInterfaceView:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:moreButton];
    self.navigationItem.rightBarButtonItem = item;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = HEXCOLOR(0xf3f3f3);
    [self setUpNavigationBar];

    backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 44)];
    backView.backgroundColor = [UIColor whiteColor];
    
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(12, 9, MainScreenWidth - 86, 26)];
    self.textField.placeholder = @"请输入关键字";
    self.textField.font = [UIFont systemFontOfSize:14.0];
    self.textField.layer.borderColor = HEXCOLOR(0xc5c5c5).CGColor;
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 20)];
    self.textField.leftViewMode = UITextFieldViewModeAlways;
    self.textField.leftView = leftView;
    self.textField.returnKeyType = UIReturnKeyDone;
    self.textField.layer.masksToBounds = YES;
    self.textField.layer.cornerRadius = 3.0;
    self.textField.layer.borderWidth = 1.0;
    self.textField.delegate = self;
    
    self.searchButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.searchButton setFrame:CGRectMake(MainScreenWidth - 62, 8, 50, 28)];
    [self.searchButton setTitle:@"搜索" forState:UIControlStateNormal];
    [self.searchButton setBackgroundColor:HEXCOLOR(0x195ac9)];
    [self.searchButton setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
    [self.searchButton addTarget:self action:@selector(doSearchButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.searchButton.layer setMasksToBounds:YES];
    [self.searchButton.layer setCornerRadius:3.0];
    
    [backView addSubview:self.textField];
    [backView addSubview:self.searchButton];
    [self.view addSubview:backView];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, backView.bottom, MainScreenWidth, MainScreenHeight - backView.bottom - NavBarHeight) style:UITableViewStyleGrouped];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;;
    self.tableView.backgroundColor = HEXCOLOR(0xf3f3f3);
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    self.tableView.showsVerticalScrollIndicator = NO;
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    NSMutableArray *refreshingImages = [NSMutableArray array];
    for (NSUInteger i = 1; i < 4; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"refresh_animation%lu", (unsigned long)i]];
        [refreshingImages addObject:image];
    }
    //  设置下拉刷新
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    [footer setTitle:CustomStr(@"RefreshBackFooterIdleText") forState:MJRefreshStateIdle];
    [footer setTitle:CustomStr(@"RefreshBackFooterPullingText") forState:MJRefreshStatePulling];
    [footer setTitle:CustomStr(@"RefreshBackFooterRefreshingText") forState:MJRefreshStateRefreshing];
    [footer setTitle:CustomStr(@"RefreshBackFooterNoMoreDataText") forState:MJRefreshStateNoMoreData];
    self.tableView.mj_footer = footer;
    self.tableView.mj_footer.hidden = YES;
    
    self.errorLabe = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - NavBarHeight)];
    self.errorLabe.backgroundColor = [UIColor clearColor];
    self.errorLabe.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.errorLabe];
    self.errorLabe.text = @"抱歉,搜索不到与关键词相关内容";
    self.errorLabe.hidden = YES;
    
    self.screenBackView = [[UIView alloc] initWithFrame:CGRectMake(MainScreenWidth, 0, MainScreenWidth, MainScreenHeight - NavBarHeight)];
    self.screenBackView.backgroundColor = [UIColor colorWithRed:15/255.0 green:24/255.0 blue:40/255.0 alpha:0.3];
    [self.view addSubview:self.screenBackView];
    
    self.screenTableView = [[UITableView alloc] initWithFrame:CGRectMake(MainScreenWidth, 40, MainScreenWidth - 40, MainScreenHeight - 40 - NavBarHeight) style:UITableViewStyleGrouped];
    self.screenTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.screenTableView.backgroundColor = [UIColor whiteColor];
    self.screenTableView.dataSource = self;
    self.screenTableView.delegate = self;
    [self.view addSubview:self.screenTableView];
    self.screenTableView.showsVerticalScrollIndicator = NO;
    if ([self.screenTableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.screenTableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    self.closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.closeButton setFrame:CGRectZero];
    [self.closeButton addTarget:self action:@selector(showScreenInterfaceView:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.closeButton];
    
    self.reSetButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.reSetButton setFrame:CGRectMake(MainScreenWidth, MainScreenHeight - 40  - NavBarHeight, MainScreenWidth - 40, 40)];
    [self.reSetButton setTitle:@"重置" forState:UIControlStateNormal];
    [self.reSetButton setBackgroundColor:HEXCOLOR(0xf0f0f0)];
    [self.reSetButton setTitleColor:HEXCOLOR(0x1f5cc6) forState:UIControlStateNormal];
    [self.reSetButton addTarget:self action:@selector(resetButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.reSetButton];
    
    self.doneButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.doneButton setFrame:CGRectMake(MainScreenWidth + (MainScreenWidth - 40)/2, MainScreenHeight - 40 - NavBarHeight, (MainScreenWidth - 40)/2, 40)];
    [self.doneButton setTitle:@"确定" forState:UIControlStateNormal];
    [self.doneButton setBackgroundColor:HEXCOLOR(0x1f5cc6)];
    [self.doneButton setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
    [self.doneButton addTarget:self action:@selector(doneButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.doneButton];
    
    searchTime = @"";
    searchCategory = @"";
    isShowResult = NO;
    isShowScreenInterface = NO;
    isTimeSelected = NO;
    isCategorySelected = NO;
    
    _historyArray = [[NSMutableArray alloc] init];
    _resultArray = [[NSMutableArray alloc] init];
    _screenArray = [[NSMutableArray alloc] init];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:(BOOL)animated];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self getSearchHistoryData];
    [self loadScreenData];
}
- (void)loadScreenData {
    NSString *strUrl = REQUESTURL(@"gxb/api/page");
    NSLog(@"%@",strUrl);
    NSDictionary *parameters = @{@"params":@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"pageUUID\":\"b73ec15c-0d1b-11e6-b082-c7d8a7a18cc4\",\"pageType\":\"channelList\"}"};
    NSLog(@"%@",parameters);
    if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
        [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
        return;
    }
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strUrl
       parameters:parameters headers:nil
         progress:^(NSProgress * _Nonnull uploadProgress) {}
          success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
              // 请求成功,解析数据
              NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
              NSLog(@"%@", dic);
              if ([dic[@"errorCode"] isEqualToString:@"0"]) {
                  NSDictionary *timeDic = dic[@"timeList"];
                  NSDictionary *conferenceDic = dic[@"conference"];
                  NSDictionary *spzlDic = dic[@"spzl"];
                  NSDictionary *wzDic = dic[@"wz"];
                  NSArray *times = [NSArray arrayWithObjects:timeDic, nil];
                  NSArray *array = [NSArray arrayWithObjects:conferenceDic,spzlDic, wzDic, nil];
                  _screenArray = [NSMutableArray arrayWithObjects:times, array, nil];
                  [self.screenTableView reloadData];
              } else {
//                  [SVProgressHUD showErrorWithStatus:dic[@"errorMessage"] duration:0.5];
                  [AlertViewTool showHUDAddedToView:self.view text:dic[@"errorMessage"]];

              }
          }
          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              // 请求失败
              [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"ServerBusy")];
          }];
}
// 获取本地存储的搜索历史
- (void)getSearchHistoryData {
    NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachePath = [cachePaths objectAtIndex:0];
    
    NSString *filePath = [cachePath stringByAppendingPathComponent:SEARCH_HISTORY];
    
    NSArray *historyArr = [NSArray arrayWithContentsOfFile:filePath];
    NSLog(@"%@",historyArr);
    
    _historyArray = [NSMutableArray arrayWithArray:historyArr];
}
//  保存搜索数据
- (void)saveSearchHistoryData:(NSString *)searchText {
    NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachePath = [cachePaths objectAtIndex:0];
    NSString *filePath = [cachePath stringByAppendingPathComponent:SEARCH_HISTORY];
    NSArray *historyArr = [NSArray arrayWithContentsOfFile:filePath];
    if ([historyArr containsObject:searchText]) {
        NSLog(@"%@",historyArr);
        return;
    }
    NSMutableArray *nHistoryArr = [NSMutableArray arrayWithArray:historyArr];
    [nHistoryArr insertObject:searchText atIndex:0];
    [nHistoryArr writeToFile:filePath atomically:YES];
}
- (void)deleteSearchHistoryDataAtIndex:(NSInteger)index  deleteAll:(BOOL)isAll {
    NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cachePath = [cachePaths firstObject];
    NSString *filePath = [cachePath stringByAppendingPathComponent:SEARCH_HISTORY];
    if (!isAll) {
        NSArray *historyArr = [NSArray arrayWithContentsOfFile:filePath];
        
        NSMutableArray *nHistoryArr = [NSMutableArray arrayWithArray:historyArr];
        [nHistoryArr removeObjectAtIndex:index];
        [nHistoryArr writeToFile:filePath atomically:YES];
    } else {
        NSFileManager *fileManager = [NSFileManager defaultManager];
        BOOL isExit = [fileManager fileExistsAtPath:filePath];
        if (isExit) {
            NSError *error;
            [fileManager removeItemAtPath:filePath error:&error];
        }
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    NSInteger number = 0;
    if ([tableView isEqual:self.tableView]) {
        number = 1;
    } else if ([tableView isEqual:self.screenTableView]) {
        number = 2;
    }
    return number;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger number = 0;
    if ([tableView isEqual:self.tableView]) {
        if (!isShowResult) {
            number = [self.historyArray count];
        } else {
            number = [self.resultArray count];
        }
    } else if ([tableView isEqual:self.screenTableView]) {
        if (0 == section) {
            number = [[_screenArray firstObject] count];
        } else if (1 == section) {
            if ([_screenArray count] > 0)
                number = [_screenArray[1] count];
        }
    }
    return number;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    CGFloat height = 0.0f;
    if ([tableView isEqual:self.tableView]) {
        if (!isShowResult) {
            if (0 == [self.historyArray count]) {
                height = 0.001f;
            } else {
                height = 40.0f;
            }
        } else {
            height = 0.001f;
        }
    } else if ([tableView isEqual:self.screenTableView]) {
        if (0 == section) {
            height = 40.0f;
        } else if (1 == section) {
            height = 40.0f;
        }
    }
    return  height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    CGFloat height = 0.0f;
    if ([tableView isEqual:self.tableView]) {
        if (!isShowResult) {
            if (0 == [self.historyArray count]) {
                height = 0.001f;
            } else {
                height = 40.0f;
            }
        } else {
            height = 0.001f;
        }
    } else if ([tableView isEqual:self.screenTableView]) {
        if (0 == section) {
            height = 0.001f;
        } else if (1 == section) {
            height = 0.001f;
        }
    }
    return  height;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if ([tableView isEqual:self.tableView]) {
        if (isShowResult) {
            return  [[UIView alloc] init];
        } else {
            if (0 == [self.historyArray count]) {
                return  [[UIView alloc] init];
            } else {
                UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 40)];
                UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, MainScreenWidth - 24, 40)];
                titleLabel.backgroundColor = [UIColor clearColor];
                titleLabel.textColor = HEXCOLOR(0x333333);
                titleLabel.font = [UIFont systemFontOfSize:14.0];
                titleLabel.text = @"搜索历史";
                [view addSubview:titleLabel];
                return view;
            }
        }
    } else if ([tableView isEqual:self.screenTableView]) {
        if (0 == section) {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 40)];
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, MainScreenWidth - 24, 40)];
            titleLabel.backgroundColor = [UIColor clearColor];
            titleLabel.textColor = HEXCOLOR(0x9d9d9d);
            titleLabel.font = [UIFont systemFontOfSize:14.0];
            titleLabel.text = @"时间筛选";
            [view addSubview:titleLabel];
            return view;
        } else if (1 == section) {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, 40)];
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, MainScreenWidth - 24, 40)];
            titleLabel.backgroundColor = [UIColor clearColor];
            titleLabel.textColor = HEXCOLOR(0x9d9d9d);
            titleLabel.font = [UIFont systemFontOfSize:14.0];
            titleLabel.text = @"栏目筛选";
            [view addSubview:titleLabel];
            return view;
        }
    }
    return  [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if ([tableView isEqual:self.tableView]) {
        if (isShowResult) {
            return  [[UIView alloc] init];
        } else {
            if (0 == [self.historyArray count]) {
                return  [[UIView alloc] init];
            } else {
                UIButton *_clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
                [_clearBtn setTitle:@"清空搜索记录" forState:UIControlStateNormal];
                [_clearBtn addTarget:self action:@selector(clearAllButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
                [_clearBtn setTitleColor:HEXCOLOR(0xadaeae) forState:UIControlStateNormal];
                [_clearBtn.titleLabel setFont:[UIFont systemFontOfSize:12.0]];
                [_clearBtn setFrame:CGRectMake(0, 0, MainScreenWidth, 44)];
                return _clearBtn;
            }
        }
    } else if ([tableView isEqual:self.screenTableView]) {
        return  [[UIView alloc] init];
    }
    return  [[UIView alloc] init];
}
-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
    CGFloat height = 0.0;
    if ([tableView isEqual:self.tableView]) {
        if (!isShowResult) {
            height = 44.0;
        }else{
            height = 100;
        }
    } else if ([tableView isEqual:self.screenTableView]) {
        if (0 == indexPath.section) {
            NSArray *timeArray = [_screenArray firstObject];
            NSDictionary *timeDic = [timeArray firstObject];
            NSArray *array = timeDic[@"programs"];
            NSInteger timeCount = [array count];
            height = 34*ceil(timeCount/4.0);
        } else if (1 == indexPath.section) {
            if (0 == indexPath.row) {
                NSArray *timeArray = _screenArray[1];
                NSDictionary *timeDic = timeArray[0];
                NSArray *array = timeDic[@"programs"];
                NSInteger timeCount = [array count];
                height = 20 + 34*ceil(timeCount/3.0);
            } else if (1 == indexPath.row) {
                NSArray *timeArray = _screenArray[1];
                NSDictionary *timeDic = timeArray[1];
                NSArray *array = timeDic[@"programs"];
                NSInteger timeCount = [array count];
                height = 20 + 34*ceil(timeCount/3.0);
            } else if (2 == indexPath.row) {
                NSArray *timeArray = _screenArray[1];
                NSDictionary *timeDic = timeArray[2];
                NSArray *array = timeDic[@"programs"];
                NSInteger timeCount = [array count];
                height = 20 + 34*ceil(timeCount/3.0);
            }
        }
    }
    return height;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.tableView]) {
        if (isShowResult) {
            NSDictionary *_dic = _resultArray[indexPath.row];
            if ([@"program" isEqualToString:_dic[@"type"]]) {
                static NSString *identifier = @"videoCell";
                VideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
                if (cell == nil) {
                    cell = [[VideoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                }
                [cell.backImage sd_setImageWithURL:[NSURL URLWithString:_dic[@"img"]] placeholderImage:[UIImage imageNamed:@"backDefault"]];
                cell.playImage.image = [UIImage imageNamed:@"playButton"];
                cell.titleLabel.text = _dic[@"title"];
                cell.timeLabel.text  = [_dic[@"createDate"] componentsSeparatedByString:@" "][0];
                NSString *text = [NSString stringWithFormat:@"%@",_dic[@"tags"]];
                if ([text isEqualToString:@"<null>"]) {
                    text = @"";
                }
                if (_dic[@"titleColor"]) {
                    cell.titleLabel.textColor = [UIColor colorWithHexString:_dic[@"titleColor"]];
                }
                if (_dic[@"tagsColor"]) {
                    cell.tagsLabel.backgroundColor = [UIColor colorWithHexString:_dic[@"tagsColor"]];
                }
                cell.tagsLabel.text  = text;
                [cell reSetTagFrame];
                return cell;
            }
            else if ([@"subject" isEqualToString:_dic[@"type"]]) {
                static NSString *identifier = @"articleCell";
                ArticleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
                if (cell == nil) {
                    cell = [[ArticleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                }
                [cell.backImage sd_setImageWithURL:[NSURL URLWithString:_dic[@"img"]] placeholderImage:[UIImage imageNamed:@"backDefault"]];
                cell.titleLabel.text = _dic[@"title"];
                cell.timeLabel.text  = [_dic[@"createDate"] componentsSeparatedByString:@" "][0];
                NSString *text = [NSString stringWithFormat:@"%@",_dic[@"tags"]];
                if ([text isEqualToString:@"<null>"]||[text isEqualToString:@""]) {
                    text = @"专题";
                }
                cell.tagsLabel.text  = text;
                [cell reSetTagFrame];
                return cell;
            }
            else if ([@"article" isEqualToString:_dic[@"type"]]) {
                
                if ([@"" isEqualToString:_dic[@"img"]]) {
                    static NSString *identifier = @"NoticeCell";
                    NoticeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
                    if (cell == nil) {
                        cell = [[NoticeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                    }
                    cell.titleLabel.text = _dic[@"title"];
                    cell.timeLabel.text  = [_dic[@"createDate"] componentsSeparatedByString:@" "][0];
                    NSString *text = [NSString stringWithFormat:@"%@",_dic[@"tags"]];
                    if ([text isEqualToString:@"<null>"]) {
                        text = @"";
                    }
                    cell.tagsLabel.text  = text;
                    [cell reSetTagFrame];
                    return cell;
                } else {
                    static NSString *identifier = @"articleCell";
                    ArticleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
                    if (cell == nil) {
                        cell = [[ArticleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                    }
                    [cell.backImage sd_setImageWithURL:[NSURL URLWithString:_dic[@"img"]] placeholderImage:[UIImage imageNamed:@"backDefault"]];
                    cell.titleLabel.text = _dic[@"title"];
                    cell.timeLabel.text  = [_dic[@"createDate"] componentsSeparatedByString:@" "][0];
                    NSString *text = [NSString stringWithFormat:@"%@",_dic[@"tags"]];
                    if ([text isEqualToString:@"<null>"]) {
                        text = @"";
                    }
                    cell.tagsLabel.text  = text;
                    [cell reSetTagFrame];
                    return cell;
                }
            } else if ([@"LK" isEqualToString:_dic[@"type"]]) {
                static NSString *identifier = @"LKCell";
                ArticleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
                if (cell == nil) {
                    cell = [[ArticleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                }
                [cell.backImage sd_setImageWithURL:[NSURL URLWithString:_dic[@"img"]] placeholderImage:[UIImage imageNamed:@"backDefault"]];
                cell.titleLabel.text = _dic[@"title"];
                cell.timeLabel.text  = [_dic[@"createDate"] componentsSeparatedByString:@" "][0];
                NSString *text = [NSString stringWithFormat:@"%@",_dic[@"tags"]];
                if ([text isEqualToString:@"<null>"]) {
                    text = @"";
                }
                cell.tagsLabel.text  = text;
                [cell reSetTagFrame];
                return cell;
            }
        } else {
            static NSString *identifier = @"historyCell";
            SearchHistoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            if (cell == nil) {
                cell = [[SearchHistoryTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            }
            cell.titleLabel.text = self.historyArray[indexPath.row];
            [cell.closeBtn addTarget:self action:@selector(clearButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
            cell.closeBtn.tag = indexPath.row;
            return cell;
        }
    } else if ([tableView isEqual:self.screenTableView]) {
        if (0 == indexPath.section) {
            static NSString *identifier = @"cell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            } else {
                for (UIView *view in cell.contentView.subviews) {
                    [view removeFromSuperview];
                }
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            NSArray *timeArray = [_screenArray firstObject];
            NSDictionary *timeDic = [timeArray firstObject];
            NSArray *array = timeDic[@"programs"];
            NSInteger timeCount = [array count];
            
            for (int i = 0; i < timeCount; i++) {
                CGFloat buttonWidth = (MainScreenWidth - 40 - 48)/4;
                CGFloat x = 12 + (i%4)*(buttonWidth + 8);
                CGFloat y = 5 + 34*floor(i/4.0);
                NSDictionary *dic = array[i];
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
                [btn setFrame:CGRectMake(x, y, buttonWidth, 24)];
                [btn setTitle:dic[@"title"] forState:UIControlStateNormal];
                if (isTimeSelected && (timeIndex == [dic[@"title"] integerValue])) {
                    [btn setBackgroundColor:HEXCOLOR(0x1f5cc6)];
                    [btn setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
                } else {
                    [btn setBackgroundColor:HEXCOLOR(0xf0f0f0)];
                    [btn setTitleColor:HEXCOLOR(0x484848) forState:UIControlStateNormal];
                }
                [btn addTarget:self action:@selector(timeSelected:) forControlEvents:UIControlEventTouchUpInside];
                [btn setTag:[dic[@"title"] integerValue]];
                [btn.layer setMasksToBounds:YES];
                [btn.layer setCornerRadius:3.0];
                [cell.contentView addSubview:btn];
            }
            return cell;
        } else if (1 == indexPath.section) {
            if (0 == indexPath.row) {
                static NSString *identifier = @"cell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                } else {
                    for (UIView *view in cell.contentView.subviews) {
                        [view removeFromSuperview];
                    }
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                NSArray *timeArray = _screenArray[1];
                NSDictionary *timeDic = timeArray[0];
                NSArray *array = timeDic[@"programs"];
                NSInteger timeCount = [array count];
                
                NSString *title = timeDic[@"title"];
                NSDictionary *titleAttributeDic = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]};
                CGSize titleSize = [title boundingRectWithSize:CGSizeMake(MainScreenWidth, MainScreenHeight) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:titleAttributeDic context:nil].size;
                CGFloat lineWidth = (MainScreenWidth - 40 - 24 - 10 - titleSize.width)/2;
                
                UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(12, 10, lineWidth, 1)];
                line1.backgroundColor = HEXCOLOR(0xf0f0f0);
                
                UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12 + lineWidth, 0, titleSize.width + 10, 20)];
                titleLabel.textColor = HEXCOLOR(0x9d9d9d);
                titleLabel.font = [UIFont systemFontOfSize:12.0f];
                titleLabel.textAlignment = NSTextAlignmentCenter;
                titleLabel.text = title;
                
                UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(12 + lineWidth + titleSize.width + 10, 10, lineWidth, 1)];
                line2.backgroundColor = HEXCOLOR(0xf0f0f0);
                
                [cell.contentView addSubview:line1];
                [cell.contentView addSubview:titleLabel];
                [cell.contentView addSubview:line2];
                
                for (int i = 0; i < timeCount; i++) {
                    CGFloat buttonWidth = (MainScreenWidth - 40 - 36)/3;
                    CGFloat x = 12 + (i%3)*(buttonWidth + 6);
                    CGFloat y = 25 + 34*floor(i/3.0);
                    NSDictionary *dic = array[i];
                    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
                    [btn setFrame:CGRectMake(x, y, buttonWidth, 24)];
                    [btn setTitle:dic[@"title"] forState:UIControlStateNormal];
                    if (isCategorySelected && (1000 + i == categoryIndex)) {
                        [btn setBackgroundColor:HEXCOLOR(0x1f5cc6)];
                        [btn setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
                    } else {
                        [btn setBackgroundColor:HEXCOLOR(0xf0f0f0)];
                        [btn setTitleColor:HEXCOLOR(0x484848) forState:UIControlStateNormal];
                    }
                    [btn addTarget:self action:@selector(categorySelected:) forControlEvents:UIControlEventTouchUpInside];
                    [btn setTag:1000 + i];
                    [btn.layer setMasksToBounds:YES];
                    [btn.layer setCornerRadius:3.0];
                    [cell.contentView addSubview:btn];
                }
                return  cell;
            } else if (1 == indexPath.row) {
                static NSString *identifier = @"cell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                } else {
                    for (UIView *view in cell.contentView.subviews) {
                        [view removeFromSuperview];
                    }
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                NSArray *timeArray = _screenArray[1];
                NSDictionary *timeDic = timeArray[1];
                NSArray *array = timeDic[@"programs"];
                NSInteger timeCount = [array count];
                
                NSString *title = timeDic[@"title"];
                NSDictionary *titleAttributeDic = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]};
                CGSize titleSize = [title boundingRectWithSize:CGSizeMake(MainScreenWidth, MainScreenHeight) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:titleAttributeDic context:nil].size;
                CGFloat lineWidth = (MainScreenWidth - 40 - 24 - 10 - titleSize.width)/2;
                
                UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(12, 10, lineWidth, 1)];
                line1.backgroundColor = HEXCOLOR(0xf0f0f0);
                
                UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12 + lineWidth, 0, titleSize.width + 10, 20)];
                titleLabel.textColor = HEXCOLOR(0x9d9d9d);
                titleLabel.font = [UIFont systemFontOfSize:12.0f];
                titleLabel.textAlignment = NSTextAlignmentCenter;
                titleLabel.text = title;
                
                UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(12 + lineWidth + titleSize.width + 10, 10, lineWidth, 1)];
                line2.backgroundColor = HEXCOLOR(0xf0f0f0);
                
                [cell.contentView addSubview:line1];
                [cell.contentView addSubview:titleLabel];
                [cell.contentView addSubview:line2];
                
                for (int i = 0; i < timeCount; i++) {
                    CGFloat buttonWidth = (MainScreenWidth - 40 - 36)/3;
                    CGFloat x = 12 + (i%3)*(buttonWidth + 6);
                    CGFloat y = 25 + 34*floor(i/3.0);
                    NSDictionary *dic = array[i];
                    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
                    [btn setFrame:CGRectMake(x, y, buttonWidth, 24)];
                    [btn setTitle:dic[@"title"] forState:UIControlStateNormal];
                    if (isCategorySelected && (2000 + i == categoryIndex)) {
                        [btn setBackgroundColor:HEXCOLOR(0x1f5cc6)];
                        [btn setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
                    } else {
                        [btn setBackgroundColor:HEXCOLOR(0xf0f0f0)];
                        [btn setTitleColor:HEXCOLOR(0x484848) forState:UIControlStateNormal];
                    }
                    [btn addTarget:self action:@selector(categorySelected:) forControlEvents:UIControlEventTouchUpInside];
                    [btn setTag:2000 + i];
                    [btn.layer setMasksToBounds:YES];
                    [btn.layer setCornerRadius:3.0];
                    [cell.contentView addSubview:btn];
                }
                return  cell;
            } else if (2 == indexPath.row) {
                static NSString *identifier = @"cell";
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
                } else {
                    for (UIView *view in cell.contentView.subviews) {
                        [view removeFromSuperview];
                    }
                }
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                NSArray *timeArray = _screenArray[1];
                NSDictionary *timeDic = timeArray[2];
                NSArray *array = timeDic[@"programs"];
                NSInteger timeCount = [array count];
                
                NSString *title = timeDic[@"title"];
                NSDictionary *titleAttributeDic = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]};
                CGSize titleSize = [title boundingRectWithSize:CGSizeMake(MainScreenWidth, MainScreenHeight) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:titleAttributeDic context:nil].size;
                CGFloat lineWidth = (MainScreenWidth - 40 - 24 - 10 - titleSize.width)/2;
                
                UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(12, 10, lineWidth, 1)];
                line1.backgroundColor = HEXCOLOR(0xf0f0f0);
                
                UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(12 + lineWidth, 0, titleSize.width + 10, 20)];
                titleLabel.textColor = HEXCOLOR(0x9d9d9d);
                titleLabel.font = [UIFont systemFontOfSize:12.0f];
                titleLabel.textAlignment = NSTextAlignmentCenter;
                titleLabel.text = title;
                
                UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(12 + lineWidth + titleSize.width + 10, 10, lineWidth, 1)];
                line2.backgroundColor = HEXCOLOR(0xf0f0f0);
                
                [cell.contentView addSubview:line1];
                [cell.contentView addSubview:titleLabel];
                [cell.contentView addSubview:line2];
                
                for (int i = 0; i < timeCount; i++) {
                    CGFloat buttonWidth = (MainScreenWidth - 40 - 36)/3;
                    CGFloat x = 12 + (i%3)*(buttonWidth + 6);
                    CGFloat y = 25 + 34*floor(i/3.0);
                    NSDictionary *dic = array[i];
                    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
                    [btn setFrame:CGRectMake(x, y, buttonWidth, 24)];
                    [btn setTitle:dic[@"title"] forState:UIControlStateNormal];
                    if (isCategorySelected && (3000 + i == categoryIndex)) {
                        [btn setBackgroundColor:HEXCOLOR(0x1f5cc6)];
                        [btn setTitleColor:HEXCOLOR(0xffffff) forState:UIControlStateNormal];
                    } else {
                        [btn setBackgroundColor:HEXCOLOR(0xf0f0f0)];
                        [btn setTitleColor:HEXCOLOR(0x484848) forState:UIControlStateNormal];
                    }
                    [btn addTarget:self action:@selector(categorySelected:) forControlEvents:UIControlEventTouchUpInside];
                    [btn setTag:3000 + i];
                    [btn.layer setMasksToBounds:YES];
                    [btn.layer setCornerRadius:3.0];
                    [cell.contentView addSubview:btn];
                }
                return  cell;
            }
        }
    }
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}
- (void)timeSelected:(id)sender{
    if (!isTimeSelected) {
        isTimeSelected = YES;
        UIButton *btn = (UIButton *)sender;
        timeIndex = btn.tag;
        searchTime = btn.titleLabel.text;
    } else {
        UIButton *btn = (UIButton *)sender;
        if (btn.tag != timeIndex) {
            timeIndex = btn.tag;
            searchTime = btn.titleLabel.text;
        } else {
            return;
        }
    }
    NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:0];
    [self.screenTableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
}
- (void)categorySelected:(id)sender{
    NSArray *categoryArray = _screenArray[1];
    if (!isCategorySelected) {
        isCategorySelected = YES;
        UIButton *btn = (UIButton *)sender;
        categoryIndex = btn.tag;
        NSInteger index = ((categoryIndex/1000) - 1);
        NSDictionary *dic = [categoryArray objectAtIndex:index];
        NSArray *cidArray = dic[@"programs"];
        NSDictionary *d = cidArray[(categoryIndex%1000)];
        searchCategory = d[@"cid"];
    } else {
        UIButton *btn = (UIButton *)sender;
        if (btn.tag != categoryIndex) {
            categoryIndex = btn.tag;
            NSInteger index = ((categoryIndex/1000) - 1);
            NSDictionary *dic = [categoryArray objectAtIndex:index];
            NSArray *cidArray = dic[@"programs"];
            NSDictionary *d = cidArray[(categoryIndex%1000)];
            searchCategory = d[@"cid"];
        } else {
            return;
        }
    }
    NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:1];
    [self.screenTableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationNone];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.tableView]) {
        if (!isShowResult) {
            //搜索接口调用
            self.textField.text = self.historyArray[indexPath.row];
            [self searchRequestWithKey:self.historyArray[indexPath.row]];
            
        } else {
            NSDictionary *_dic = _resultArray[indexPath.row];
            if ([@"program" isEqualToString:_dic[@"type"]]) {
                //视频
                OldVideoDetailViewController *vc = [[OldVideoDetailViewController alloc] initWithDictionary:_dic];
                vc.title = _dic[@"cmsColumnName"];
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            } else if ([@"article" isEqualToString:_dic[@"type"]]) {
                //文章
                OldArticleDetailViewController *vc = [[OldArticleDetailViewController alloc] initWithDictionary:_dic];
                vc.title = _dic[@"cmsColumnName"];
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            } else if ([@"subject" isEqualToString:_dic[@"type"]]) {
                SCIOSpecialViewController *vc = [[SCIOSpecialViewController alloc] initWithDictionary:_dic];
                vc.title = @"国新专题";
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            } else if ([@"LK" isEqualToString:_dic[@"type"]]) {
                CNLiveWebViewController *webVC = [CNLiveWebViewController new];
                webVC.url = [NSString stringWithFormat:@"%@",_dic[@"pageUrl"]];
                webVC.isFromLH = YES;
                webVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:webVC animated:YES];
                
            }
            
        }
    
    }
    else if ([tableView isEqual:self.screenTableView]) {
        
    }
}
- (void)resetButtonClicked:(id)sender {
    isTimeSelected = NO;
    isCategorySelected = NO;
    searchTime = @"";
    searchCategory = @"";
    [self.screenTableView reloadData];
}
- (void)doneButtonClicked:(id)sender {
    if (!isTimeSelected && !isCategorySelected) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提醒" message:@"您还没有选择时间或栏目" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    [self showScreenInterfaceView:nil];
    [self searchRequestWithKey:self.textField.text andTime:searchTime andCategory:searchCategory];
    [self.view endEditing:YES];
}
- (void)searchRequestWithKey:(NSString *)searchText andTime:(NSString *)time andCategory:(NSString*)category {
    if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
        [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
        return;
    }
    
    [SVProgressHUD show];
    
    pageNumber = 1;
    searchKey = searchText;
    searchTime = time;
    searchCategory = category;
    
    searchCategoryId = [NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"categoryId\":\"%@\",\"year\":\"%@\",\"keyword\":\"%@\",\"page\":1,\"pageSize\":\"10\"}",searchCategory,searchTime,searchKey];
    NSLog(@"%@",searchCategoryId);
    NSDictionary *parameters = @{@"params":searchCategoryId};
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:searchApi
       parameters:parameters headers:nil
         progress:^(NSProgress * _Nonnull uploadProgress) {}                                     success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
             // 请求成功,解析数据
             NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
             NSLog(@"%@", dic);
             if ([dic[@"errorCode"] isEqualToString:@"0"]) {
                 if ([_resultArray count] > 0) {
                     [_resultArray removeAllObjects];
                 }
                 NSArray *array = dic[@"programs"];
                 if ([array count] > 0) {
                     backView.backgroundColor = HEXCOLOR(0xf3f3f3);
                     [_resultArray addObjectsFromArray:dic[@"programs"]];
                     self.errorLabe.hidden = YES;
                 } else {
                     backView.backgroundColor = [UIColor whiteColor];
                     self.errorLabe.hidden = NO;
                 }
                 if (![dic[@"nextCursor"] isEqualToString:@"0"]) {
                     [self.tableView.mj_footer setHidden:NO];
                 } else {
                     self.tableView.mj_footer.hidden = YES;
                 }
                 isShowResult = YES;
                 [self.tableView reloadData];
                 [SVProgressHUD dismiss];
             } else {
//                 [SVProgressHUD showErrorWithStatus:dic[@"errorMessage"] duration:0.5];
                 [AlertViewTool showHUDAddedToView:self.view text:dic[@"errorMessage"]];

             }
         }
          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              // 请求失败
              NSLog(@"%@", [error localizedDescription]);
              [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"ServerBusy")];
          }];
}
- (void)doSearchButtonClicked:(id)sender {
    if (0 == [self.textField.text length]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提醒" message:@"您还没有输入搜索内容" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
    if (IS_STRING_EMPTY(self.textField.text)) {
        NSLog(@"没有输入搜索内容");
        return;
    }
    //搜索接口调用
    [self saveSearchHistoryData:self.textField.text];
    [self searchRequestWithKey:self.textField.text];
    [self.view endEditing:YES];
}
- (void)searchRequestWithKey:(NSString *)searchText {
    if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
        [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
        return;
    }
    [SVProgressHUD show];
    
    pageNumber = 1;
    searchKey = searchText;
    
    searchCategoryId = [NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"keyword\":\"%@\",\"page\":1,\"pageSize\":\"10\"}",searchKey];
    NSLog(@"%@",searchCategoryId);
    NSDictionary *parameters = @{@"params":searchCategoryId};
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:searchApi
       parameters:parameters headers:nil
         progress:^(NSProgress * _Nonnull uploadProgress) {}                                     success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
             // 请求成功,解析数据
             NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
             NSLog(@"%@", dic);
             if ([dic[@"errorCode"] isEqualToString:@"0"]) {
                 if ([_resultArray count] > 0) {
                     [_resultArray removeAllObjects];
                 }
                 NSArray *array = dic[@"programs"];
                 if ([array count] > 0) {
                     backView.backgroundColor = HEXCOLOR(0xf3f3f3);
                     [_resultArray addObjectsFromArray:dic[@"programs"]];
                     self.errorLabe.hidden = YES;
                 } else {
                     backView.backgroundColor = [UIColor whiteColor];
                     self.errorLabe.hidden = NO;
                 }
                 if (![dic[@"nextCursor"] isEqualToString:@"0"]) {
                     [self.tableView.mj_footer setHidden:NO];
                 } else {
                     self.tableView.mj_footer.hidden = YES;
                 }
                 isShowResult = YES;
                 [self.tableView reloadData];
                 [SVProgressHUD dismiss];
             } else {
//                 [SVProgressHUD showErrorWithStatus:dic[@"errorMessage"] duration:0.5];
                 [AlertViewTool showHUDAddedToView:self.view text:dic[@"errorMessage"]];

             }
         }
          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              // 请求失败
              NSLog(@"%@", [error localizedDescription]);
              [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"ServerBusy")];
          }];
}
- (void)loadMoreData {
    if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
        [AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
        return;
    }
    
    NSString *pageString = [NSString stringWithFormat:@"\"page\":%ld",(long)pageNumber];
    
    pageNumber++;
    
    NSString *pageReplac = [NSString stringWithFormat:@"\"page\":%ld",(long)pageNumber];
    
    NSLog(@"%@",searchCategoryId);
    
    searchCategoryId = [searchCategoryId stringByReplacingOccurrencesOfString:pageString withString:pageReplac];
    
    NSLog(@"%@",searchCategoryId);
    
    NSDictionary *parameters = @{@"params":searchCategoryId};
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:searchApi
       parameters:parameters headers:nil 
         progress:^(NSProgress * _Nonnull uploadProgress) {}                                     success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
             // 请求成功,解析数据
             NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
             NSLog(@"%@", dic);
             if ([dic[@"errorCode"] isEqualToString:@"0"]) {
                 NSArray *array = dic[@"programs"];
                 [_resultArray addObjectsFromArray:array];
                 [self.tableView reloadData];
             }
             [self.tableView.mj_footer endRefreshing];
             if (![dic[@"nextCursor"] isEqualToString:@"0"]) {
                 [self.tableView.mj_footer setHidden:NO];
             } else {
                 self.tableView.mj_footer.hidden = YES;
             }
         }
          failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
              // 请求失败
              NSLog(@"%@", [error localizedDescription]);
              [AlertViewTool showHUDAddedToView:self.view text:CustomStr(@"ServerBusy")];

          }];
}
- (void)clearButtonClicked:(id)sender {
    NSLog(@"clear one");
    UIButton *btn = (UIButton*)sender;
    [self.historyArray removeObjectAtIndex:btn.tag];
    [self deleteSearchHistoryDataAtIndex:btn.tag deleteAll:NO];
    [self.tableView reloadData];
}
- (void)clearAllButtonClicked:(id)sender{
    NSLog(@"clear all");
    [self.historyArray removeAllObjects];
    [self deleteSearchHistoryDataAtIndex:0 deleteAll:YES];
    [self.tableView reloadData];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.tableView endEditing:YES];
    [self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if ([textField isEqual:self.textField]) {
        [self.textField resignFirstResponder];
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end