// // ReplayLikeSearchVC.m // smartRhino // // Created by niuzhen on 2020/1/17. // Copyright © 2020 tederen. All rights reserved. // #import "ReplayLikeSearchVC.h" #import "ReplayMeCell.h" #import "ReplyModel.h" @interface ReplayLikeSearchVC () @property (nonatomic, strong) NSMutableArray *listArray; @end @implementation ReplayLikeSearchVC - (NSMutableArray *)listArray { if (!_listArray) { _listArray = [NSMutableArray array]; } return _listArray; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.view.backgroundColor = RGB(255, 255, 255); self.tableView.delegate = self; self.tableView.dataSource = self; // [self.topNavSearch setBarPlaceholder:@"姓名/手机号/邮箱"]; self.historySearchType = HistorySearchType_LikeList; [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { id obj = [change objectForKey:@"new"]; NSString * text = @""; if ([obj isKindOfClass:[NSString class]]) { text = obj; }else{ text = [obj stringValue]; } if (text.length > 0) { [self getData:text]; } } - (void)getData:(NSString *)searchKey { [self.listArray removeAllObjects]; WS(weakSelf); NSDictionary * paraDict = @{@"KeyWord":self.searchText, @"TypeValue":@(0), }; SHOWLOADING [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Reply_Praise) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) { REMOVESHOW if ([responseObject isKindOfClass:[NSArray class]]) { for (NSDictionary * dict in responseObject) { ReplyModel * model = [ReplyModel modelWithDictionary:dict]; [weakSelf.listArray addObject:model]; } } dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { REMOVESHOW }]; } #pragma mark - UITableViewDelegate - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.listArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewAutomaticDimension; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ ReplyModel * model = [self.listArray objectAtIndex:indexPath.row]; if (model.IsComment) { ReplayMeCell * cell = [ReplayMeCell configCell0:tableView indexPath:indexPath]; cell.redV.hidden = YES; [cell setDataCommentModel:model searchText:self.searchText]; return cell; }else{ ReplayMeCell * cell = [ReplayMeCell configCell1:tableView indexPath:indexPath]; cell.redV.hidden = YES; [cell setDataModel:model searchText:self.searchText]; return cell; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; ReplyModel * model = [self.listArray objectAtIndex:indexPath.row]; MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.type = model.TypeValue; vc.Id = model.SourceId; [self.navigationController pushViewController:vc animated:YES]; } @end