// // HomeSearchDetailController.m // TheoryNetwork // // Created by tederen on 2019/9/23. // Copyright © 2019 tederen. All rights reserved. // #import "HomeSearchDetailController.h" #import "InfoSearchView.h" #import "ChannelModel.h" #import "HttpManager.h" #import "DocumentModel.h" #import "HomeTableViewCell.h" #import "HomeDetailController.h" #import "SearchDetailViewCell.h" #import @interface HomeSearchDetailController () { NSString *_searchString; //搜索内容 } @property (nonatomic, strong) InfoSearchView *topNavSearch; @property (nonatomic, strong) TDTableView *tableView; @property (nonatomic, copy) NSArray *dataArr; @property (nonatomic, strong) NSMutableArray *sourceDataArr; @end @implementation HomeSearchDetailController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidLoad { [super viewDidLoad]; [self.view addSubview:self.topNavSearch]; [self.view addSubview:self.tableView]; self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestContent)]; [self.tableView reloadData]; self.fd_prefersNavigationBarHidden = YES; } - (void)getData:(NSString *)keyword{ WEAKSELF // [self.sourceDataArr removeAllObjects]; [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Notice_list_Post] parameters: @{@"page":@1,@"perPage":@100,@"keyword":keyword} responseStyle:JOSN success:^(id _Nonnull responseObject) { STRONGSELF NSDictionary *dic = (NSDictionary *)responseObject; HomeArticleModel *model = [HomeArticleModel yy_modelWithDictionary:dic]; // HomeArticleModel *model = [[HomeArticleModel alloc] initWithDictionary:dic error:nil]; NSLog(@"首页文章 搜索数据%@=====================================",dic[@"total"]); dispatch_async(dispatch_get_main_queue(), ^{ // [strongSelf.sourceDataArr removeAllObjects]; strongSelf.sourceDataArr = [NSMutableArray arrayWithArray:model.Items]; [strongSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { NSLog(@"首页文章 数据%@",error); }]; } -(IBAction)tapAction:(id)sender{ } - (void)setCurrentSearchData:(NSString *)data { [self.topNavSearch setNowSearchData:data]; _searchString = data; [self getData:_searchString]; } #pragma mark - NetRequest - (void)requestContent { } #pragma mark - UITableViewDataSource && UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.sourceDataArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 128; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellIdentifier = NSStringFromSelector(_cmd); SearchDetailViewCell *cell = (SearchDetailViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (!cell) { cell = [[SearchDetailViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } Item *model = self.sourceDataArr[indexPath.row]; [cell loadCurrentData:model hotWord:_searchString]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { HomeDetailController *homeDetail = [[HomeDetailController alloc] init]; [homeDetail loadCurrentModel:self.sourceDataArr[indexPath.row]]; [self.navigationController pushViewController:homeDetail animated:YES]; } #pragma mark - InfoSearchViewDelegate - (void)searchButtonAction:(UISearchBar *)searchBar { [self.view endEditing:YES]; _searchString = searchBar.text; [self getData:searchBar.text]; } - (void)textDidChange:(NSString *)text { if (ISEmptyString(text) ) { [self.sourceDataArr removeAllObjects]; self.sourceDataArr = [NSMutableArray new]; [self.tableView reloadData]; } } #pragma mark - setter - (InfoSearchView *)topNavSearch { if (!_topNavSearch) { _topNavSearch = [[InfoSearchView alloc] initWithFrame:CGRectMake(0,kBooliPhoneX==YES?40:20, kGXScreenWidth, 45.f) type:InfoSearchViewTypeCancel]; _topNavSearch.delegate = self; WEAKSELF _topNavSearch.backBlock = ^{ STRONGSELF // 回首页 [strongSelf.navigationController popToRootViewControllerAnimated:YES]; }; _topNavSearch.cancelBlock = ^{ STRONGSELF // [strongSelf.navigationController popViewControllerAnimated:YES]; }; [_topNavSearch showLineView]; } return _topNavSearch; } - (TDTableView *)tableView { if (!_tableView) { _tableView = [[TDTableView alloc] init]; _tableView.frame = CGRectMake(0, (kBooliPhoneX==YES?85:65), kGXScreenWidth, kGXScreenHeigh-(kBooliPhoneX==YES?85:65)); _tableView.dataSource = self; _tableView.delegate = self; } return _tableView; } @end