123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // MyTDTopicUserSearchVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/1/1.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "MyTDTopicUserSearchVC.h"
- #import "SelectModel.h"
- #import "MyTDTopicUserMoveVC.h"
- #import "MailListByZuCell.h"
- @interface MyTDTopicUserSearchVC ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, copy) NSString * text;
- @property (nonatomic, strong) NSMutableArray * searchArray;
- @end
- @implementation MyTDTopicUserSearchVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- 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 forDataArraySearch:text];
- }
- }
- - (void)forDataArraySearch:(NSString *)text
- {
- [self.searchArray removeAllObjects];
- for (SelectModel * model in self.listArray) {
- if ([model.UserName containsString:text]) {
- [self.searchArray addObject:model];
- }
- }
- if (self.searchArray.count > 0) {
- self.collectionView.hidden = YES;
- self.noDataView.hidden = YES;
- self.tableView.hidden = NO;
- [self.tableView reloadData];
- }else{
- self.noDataView.hidden = NO;
- self.collectionView.hidden = YES;
- self.tableView.hidden = YES;
- self.noDataL.text = @"暂无成员";
- }
- }
- - (NSMutableArray *)searchArray
- {
- if (!_searchArray) {
- _searchArray = [NSMutableArray array];
- }
- return _searchArray;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.searchArray.count;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 65.f;
- }
-
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- SelectModel * model = [self.searchArray objectAtIndex:indexPath.row];
- MailListByZuCell *cell = [MailListByZuCell configCell0:tableView indexPath:indexPath];
- cell.cell0TitleLabel.text = model.UserName;
- [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
- return cell;
- }
- #pragma Mark 左滑按钮 iOS8以上
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
- - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
- WS(weakSelf);
- SelectModel * model = [self.searchArray objectAtIndex:indexPath.row];
- UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
- UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf deleteFind:@[@(model.Id)] indexPath:indexPath.row];
- }];
- UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:sureAction];
- [alert addAction:cancelAction];
- [weakSelf presentViewController:alert animated:YES completion:^{
-
- }];
- }];
- action1.backgroundColor = UIColorHex(#F64A33);
- UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"移动" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
- [weakSelf launchMoveVC:@[@(model.Id)]];
- }];
- action2.backgroundColor = RGB(61, 156, 248);
- UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1,action2]];
- actions.performsFirstActionWithFullSwipe = NO;
- return actions;
- }
- #else
- - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
- WS(weakSelf);
- SelectModel * model = [self.searchArray objectAtIndex:indexPath.row];
- UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
- UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf deleteFind:@[@(model.Id)] indexPath:indexPath.row];
- }];
- UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:sureAction];
- [alert addAction:cancelAction];
- [weakSelf presentViewController:alert animated:YES completion:^{
-
- }];
- }];
- action1.backgroundColor = UIColorHex(#F64A33);
- UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- [weakSelf launchMoveVC:@[@(model.Id)]];
- }];
- action2.backgroundColor = RGB(61, 156, 248);
- return @[action1,action2];
- }
- #endif
- - (void)deleteFind:(NSArray *)array indexPath:(NSInteger)row
- {
- WS(weakSelf);
- [[HttpManager sharedHttpManager] DeleteUrl:Host(APP_Topic_Group_User) parameters:@{@"Ids":array} responseStyle:DATA success:^(id _Nonnull responseObject) {
- [weakSelf.searchArray removeObjectAtIndex:row];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- if (weakSelf.upDateBlock) {
- weakSelf.upDateBlock();
- }
- });
- } failure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)launchMoveVC:(NSArray *)selectIDArray{
- MyTDTopicUserMoveVC * vc = [MyTDTopicUserMoveVC initMyTDTopicUserMoveVC];
- vc.selectIdArray = selectIDArray;
- if (self.upDateBlock) {
- self.upDateBlock();
- }
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)dealloc
- {
- [self removeObserver:self forKeyPath:@"searchText" context:nil];
- }
- @end
|