HomeSearchDetailController.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // HomeSearchDetailController.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/23.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "HomeSearchDetailController.h"
  9. #import "InfoSearchView.h"
  10. #import "ChannelModel.h"
  11. #import "HttpManager.h"
  12. #import "DocumentModel.h"
  13. #import "HomeTableViewCell.h"
  14. #import "HomeDetailController.h"
  15. #import "SearchDetailViewCell.h"
  16. #import <YYModel/YYModel.h>
  17. @interface HomeSearchDetailController () <UITableViewDataSource, UITableViewDelegate, InfoSearchViewDelegate> {
  18. NSString *_searchString; //搜索内容
  19. }
  20. @property (nonatomic, strong) InfoSearchView *topNavSearch;
  21. @property (nonatomic, strong) TDTableView *tableView;
  22. @property (nonatomic, copy) NSArray *dataArr;
  23. @property (nonatomic, strong) NSMutableArray <Item *>*sourceDataArr;
  24. @end
  25. @implementation HomeSearchDetailController
  26. - (void)viewWillAppear:(BOOL)animated {
  27. [super viewWillAppear:animated];
  28. }
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. [self.view addSubview:self.topNavSearch];
  32. [self.view addSubview:self.tableView];
  33. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestContent)];
  34. [self.tableView reloadData];
  35. self.fd_prefersNavigationBarHidden = YES;
  36. }
  37. - (void)getData:(NSString *)keyword{
  38. WEAKSELF
  39. // [self.sourceDataArr removeAllObjects];
  40. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Article_Notice_list_Post] parameters: @{@"page":@1,@"perPage":@100,@"keyword":keyword} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  41. STRONGSELF
  42. NSDictionary *dic = (NSDictionary *)responseObject;
  43. HomeArticleModel *model = [HomeArticleModel yy_modelWithDictionary:dic];
  44. // HomeArticleModel *model = [[HomeArticleModel alloc] initWithDictionary:dic error:nil];
  45. NSLog(@"首页文章 搜索数据%@=====================================",dic[@"total"]);
  46. dispatch_async(dispatch_get_main_queue(), ^{
  47. // [strongSelf.sourceDataArr removeAllObjects];
  48. strongSelf.sourceDataArr = [NSMutableArray arrayWithArray:model.Items];
  49. [strongSelf.tableView reloadData];
  50. });
  51. } failure:^(NSError * _Nonnull error) {
  52. NSLog(@"首页文章 数据%@",error);
  53. }];
  54. }
  55. -(IBAction)tapAction:(id)sender{
  56. }
  57. - (void)setCurrentSearchData:(NSString *)data {
  58. [self.topNavSearch setNowSearchData:data];
  59. _searchString = data;
  60. [self getData:_searchString];
  61. }
  62. #pragma mark - NetRequest
  63. - (void)requestContent {
  64. }
  65. #pragma mark - UITableViewDataSource && UITableViewDelegate
  66. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  67. return self.sourceDataArr.count;
  68. }
  69. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  70. return 128;
  71. }
  72. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  73. NSString *cellIdentifier = NSStringFromSelector(_cmd);
  74. SearchDetailViewCell *cell = (SearchDetailViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  75. if (!cell) {
  76. cell = [[SearchDetailViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  77. }
  78. Item *model = self.sourceDataArr[indexPath.row];
  79. [cell loadCurrentData:model hotWord:_searchString];
  80. return cell;
  81. }
  82. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  83. HomeDetailController *homeDetail = [[HomeDetailController alloc] init];
  84. [homeDetail loadCurrentModel:self.sourceDataArr[indexPath.row]];
  85. [self.navigationController pushViewController:homeDetail animated:YES];
  86. }
  87. #pragma mark - InfoSearchViewDelegate
  88. - (void)searchButtonAction:(UISearchBar *)searchBar {
  89. [self.view endEditing:YES];
  90. _searchString = searchBar.text;
  91. [self getData:searchBar.text];
  92. }
  93. - (void)textDidChange:(NSString *)text {
  94. if (ISEmptyString(text) ) {
  95. [self.sourceDataArr removeAllObjects];
  96. self.sourceDataArr = [NSMutableArray new];
  97. [self.tableView reloadData];
  98. }
  99. }
  100. #pragma mark - setter
  101. - (InfoSearchView *)topNavSearch {
  102. if (!_topNavSearch) {
  103. _topNavSearch = [[InfoSearchView alloc] initWithFrame:CGRectMake(0,kBooliPhoneX==YES?40:20, kGXScreenWidth, 45.f) type:InfoSearchViewTypeCancel];
  104. _topNavSearch.delegate = self;
  105. WEAKSELF
  106. _topNavSearch.backBlock = ^{
  107. STRONGSELF
  108. // 回首页
  109. [strongSelf.navigationController popToRootViewControllerAnimated:YES];
  110. };
  111. _topNavSearch.cancelBlock = ^{
  112. STRONGSELF
  113. //
  114. [strongSelf.navigationController popViewControllerAnimated:YES];
  115. };
  116. [_topNavSearch showLineView];
  117. }
  118. return _topNavSearch;
  119. }
  120. - (TDTableView *)tableView {
  121. if (!_tableView) {
  122. _tableView = [[TDTableView alloc] init];
  123. _tableView.frame = CGRectMake(0, (kBooliPhoneX==YES?85:65), kGXScreenWidth, kGXScreenHeigh-(kBooliPhoneX==YES?85:65));
  124. _tableView.dataSource = self;
  125. _tableView.delegate = self;
  126. }
  127. return _tableView;
  128. }
  129. @end