ReplayLikeSearchVC.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // ReplayLikeSearchVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/1/17.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "ReplayLikeSearchVC.h"
  9. #import "ReplayMeCell.h"
  10. #import "ReplyModel.h"
  11. @interface ReplayLikeSearchVC ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, strong) NSMutableArray *listArray;
  13. @end
  14. @implementation ReplayLikeSearchVC
  15. - (NSMutableArray *)listArray
  16. {
  17. if (!_listArray) {
  18. _listArray = [NSMutableArray array];
  19. }
  20. return _listArray;
  21. }
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.fd_prefersNavigationBarHidden = YES;
  25. self.view.backgroundColor = RGB(255, 255, 255);
  26. self.tableView.delegate = self;
  27. self.tableView.dataSource = self;
  28. // [self.topNavSearch setBarPlaceholder:@"姓名/手机号/邮箱"];
  29. self.historySearchType = HistorySearchType_LikeList;
  30. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  31. }
  32. - (void)dealloc
  33. {
  34. [[NSNotificationCenter defaultCenter] removeObserver:self];
  35. }
  36. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  37. {
  38. id obj = [change objectForKey:@"new"];
  39. NSString * text = @"";
  40. if ([obj isKindOfClass:[NSString class]]) {
  41. text = obj;
  42. }else{
  43. text = [obj stringValue];
  44. }
  45. if (text.length > 0) {
  46. [self getData:text];
  47. }
  48. }
  49. - (void)getData:(NSString *)searchKey
  50. {
  51. [self.listArray removeAllObjects];
  52. WS(weakSelf);
  53. NSDictionary * paraDict = @{@"KeyWord":self.searchText,
  54. @"TypeValue":@(0),
  55. };
  56. SHOWLOADING
  57. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Reply_Praise) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  58. REMOVESHOW
  59. if ([responseObject isKindOfClass:[NSArray class]]) {
  60. for (NSDictionary * dict in responseObject) {
  61. ReplyModel * model = [ReplyModel modelWithDictionary:dict];
  62. [weakSelf.listArray addObject:model];
  63. }
  64. }
  65. dispatch_async(dispatch_get_main_queue(), ^{
  66. [weakSelf.tableView reloadData];
  67. });
  68. } failure:^(NSError * _Nonnull error) {
  69. REMOVESHOW
  70. }];
  71. }
  72. #pragma mark - UITableViewDelegate
  73. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  74. return 1;
  75. }
  76. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  77. return self.listArray.count;
  78. }
  79. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  80. return UITableViewAutomaticDimension;
  81. }
  82. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  83. ReplyModel * model = [self.listArray objectAtIndex:indexPath.row];
  84. if (model.IsComment) {
  85. ReplayMeCell * cell = [ReplayMeCell configCell0:tableView indexPath:indexPath];
  86. cell.redV.hidden = YES;
  87. [cell setDataCommentModel:model searchText:self.searchText];
  88. return cell;
  89. }else{
  90. ReplayMeCell * cell = [ReplayMeCell configCell1:tableView indexPath:indexPath];
  91. cell.redV.hidden = YES;
  92. [cell setDataModel:model searchText:self.searchText];
  93. return cell;
  94. }
  95. }
  96. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  97. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  98. ReplyModel * model = [self.listArray objectAtIndex:indexPath.row];
  99. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  100. vc.type = model.TypeValue;
  101. vc.Id = model.SourceId;
  102. [self.navigationController pushViewController:vc animated:YES];
  103. }
  104. @end