123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //
- // ReadSearchVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/3/13.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "ReadSearchVC.h"
- #import "MailListByZuCell.h"
- #import "MailListDetailVC.h"
- @interface ReadSearchVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, copy) NSMutableArray * listArray;
- @end
- @implementation ReadSearchVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = YES;
- self.view.backgroundColor = RGB(255, 255, 255);
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.historySearchType = HistorySearchType_MailList;
- [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)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.listArray removeAllObjects];
- [self getData:text];
- }
- }
- - (void)getData:(NSString *)text
- {
- for (SelectModel * model in self.dataArray) {
- if ([model.UserName containsString:text]) {
- [self.listArray addObject:model];
- }
- }
- WS(weakSelf);
- dispatch_async(dispatch_get_main_queue(), ^{
- if (weakSelf.listArray.count > 0) {
- weakSelf.collectionView.hidden = YES;
- weakSelf.noDataView.hidden = YES;
- weakSelf.tableView.hidden = NO;
- [weakSelf.tableView reloadData];
- }else{
- weakSelf.noDataView.hidden = NO;
- weakSelf.collectionView.hidden = YES;
- weakSelf.tableView.hidden = YES;
- weakSelf.noDataL.text = @"暂无用户";
- }
- });
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.listArray.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return [MailListByZuCell configCell2Height];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- SelectModel * model = [self.listArray objectAtIndex:indexPath.row];
- MailListByZuCell *cell = [MailListByZuCell configCell2:tableView indexPath:indexPath];
- cell.cell0TitleLabel.text = model.UserName;
- cell.cell0DepartMentName.hidden = YES;
- [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:IMG(@"chatmsg_list_testuser_img")];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- SelectModel *model = [self.listArray objectAtIndex:indexPath.row];
- model.SourceName = model.UserName;
- model.SourceId = model.UserId;
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- MailListDetailVC *vc = [MailListDetailVC initMailListDetailVC];
- vc.indexId = model.SourceId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (NSMutableArray *)listArray{
- if (!_listArray) {
- _listArray = [NSMutableArray new];
- }
- return _listArray;
- }
- @end
|