// // PropsUseVC.m // IBOSS // // Created by 关宏厚 on 2019/9/16. // Copyright © 2019 elongtian. All rights reserved. // #import "PropsUseVC.h" @interface PropsUseVC () @end @implementation PropsUseVC - (void)viewDidLoad { [super viewDidLoad]; //是否是dismissViewController if (_isPresentViewFlg) { UIView *vTitle = [[UIView alloc]init]; vTitle.frame = CGRectMake(0, 0, Screen_Width, 44 + rectStatusHeight); vTitle.backgroundColor = NavigationBarTintColor; [self.view addSubview:vTitle]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(gotoBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(20, rectStatusHeight + 13, 9, 15); [vTitle addSubview:button]; UILabel *lblTitle = [[UILabel alloc]init]; lblTitle.frame = CGRectMake(9, rectStatusHeight + 13, Screen_Width-2*9 - 20, 15); lblTitle.textColor = [UIColor whiteColor]; lblTitle.text = @"请选择"; lblTitle.textAlignment = NSTextAlignmentCenter; [vTitle addSubview:lblTitle]; }else{ self.navigationItem.title = @"请选择"; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(gotoBack) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0,45,22); UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = menuButton; [self.navigationController setNavigationBarHidden:NO]; } _tableView = [UITableView new]; //是否是dismissViewController if (_isPresentViewFlg) { self.tableView.frame = CGRectMake(0, 44 + rectStatusHeight, self.view.bounds.size.width, self.view.bounds.size.height - 44 - rectStatusHeight - 1) ; } else{ self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-rectNavHeight - rectStatusHeight - 1) ; } [self.view addSubview:_tableView]; self.arrSearch = [[NSMutableArray alloc] init] ; self.arrFilter = [[NSMutableArray alloc] init] ; //搜索框 _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)]; _searchBar.delegate=self; self.tableView.tableHeaderView=_searchBar; self.arrSearch = [[NSMutableArray alloc]initWithArray:_propsList]; self.arrFilter = [[NSMutableArray alloc] initWithArray:_arrSearch]; _tableView.delegate=self; _tableView.dataSource=self; [_tableView reloadData]; } /** viewWillAppear @param animated <#animated description#> */ - (void)viewWillAppear:(BOOL)animated { } #pragma mark - tableView回调 /** Section @param tableView <#tableView description#> @return <#return value description#> */ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } /** 单元格个数 @param tableView <#tableView description#> @param section <#section description#> @return <#return value description#> */ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.arrFilter.count; } /** 每个单元格 @param tableView <#tableView description#> @param indexPath <#indexPath description#> @return <#return value description#> */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ]; if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } NSDictionary *dic = self.arrFilter[indexPath.row]; cell.textLabel.text = [dic objectForKey:@"DictionaryValue"]; cell.textLabel.textAlignment = NSTextAlignmentCenter; cell.textLabel.font = [UIFont systemFontOfSize:TextFontOfSize]; return cell; } /** 单元格点击事件 @param tableView <#tableView description#> @param indexPath <#indexPath description#> */ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSDictionary *dic=self.arrFilter[indexPath.row]; BaseIDAndNameModel *model = [BaseIDAndNameModel new]; model.name = [dic objectForKey:@"DictionaryValue"]; if ([self.bDelegate respondsToSelector:@selector(baseIDAndNameDoneDatas : BaseIDAndName:)]){ [self.bDelegate baseIDAndNameDoneDatas:model BaseIDAndName:self.showDialogViewTag]; } //是否是dismissViewController if (_isPresentViewFlg) { [self dismissViewControllerAnimated:YES completion:nil]; }else{ [self.navigationController popViewControllerAnimated:YES]; } } /** 开始编辑 @param searchBar <#searchBar description#> @return <#return value description#> */ - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { [self addCancelButton]; return YES; } /** 是否可以查询 @param searchBar <#searchBar description#> @param range <#range description#> @param text <#text description#> @return <#return value description#> */ - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { return YES; } /** 文本变化 @param searchBar <#searchBar description#> @param searchText <#searchText description#> */ - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { if ([searchText isEqualToString:@""]) { self.arrFilter = _arrSearch; [_tableView reloadData]; return; } NSString *keyName = @"DictionaryValue"; //< 模糊查找 NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@", keyName, searchText]; NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearch filteredArrayUsingPredicate:predicateString]]; self.arrFilter = filteredArray; [_tableView reloadData]; } /** 查询点击事件 @param searchBar <#searchBar description#> */ - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [searchBar resignFirstResponder]; [self cancelSearch]; } /** 开始拖动 @param scrollView <#scrollView description#> */ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { [_searchBar resignFirstResponder]; [self cancelSearch]; } #pragma mark - 私有函数 /** 进度条隐藏 */ - (void)cancel { [self stopLoading]; } /** 添加取消按钮 */ - (void)addCancelButton { //添加取消按钮 UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:self action:@selector(cancelSearch) forControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(0, 0, 40, 24); [button setTitle:@"取消" forState:UIControlStateNormal]; [button setTitleColor:NavBarItemColor forState:UIControlStateNormal]; UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.rightBarButtonItem = menuButton; } /** 取消查询 */ - (void)cancelSearch { [_searchBar resignFirstResponder]; [self removeCancel]; } /** 取消按钮隐藏 */ - (void) removeCancel { self.navigationItem.rightBarButtonItem = nil; } /** 返回父界面 */ - (void)gotoBack { //是否是dismissViewController if (_isPresentViewFlg) { [self dismissViewControllerAnimated:YES completion:nil]; }else{ [self.navigationController popViewControllerAnimated:YES]; } } @end