| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- //
- // ResponsiblePersonViewController.m
- // IBOSSmini
- //
- // Created by apple on 2017/5/27.
- // Copyright © 2017年 elongtian. All rights reserved.
- //
- #import "ResponsiblePersonViewController.h"
- #import "ResponsiblePersonCell.h"
- @interface ResponsiblePersonViewController ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>
- @property(nonatomic,strong) UISearchBar *searchBar;
- @property(nonatomic,strong) UITableView *tableViewPerson;
- @end
- @implementation ResponsiblePersonViewController
- #pragma mark - 公共事件
- /**
- viewDidLoad事件
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.navigationItem.title=@"请选择";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"icon_back"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(sGotoBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- [self.navigationController setNavigationBarHidden:NO];
-
- self.tableViewPerson=[UITableView new];
- self.tableViewPerson.dataSource=self;
- self.tableViewPerson.delegate=self;
-
- self.tableViewPerson.frame=CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-rectNavHeight - rectStatusHeight - 1) ;
-
- [self.view addSubview:self.tableViewPerson];
-
- //搜索框
- self.searchBar=[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
- self.searchBar.delegate=self;
- self.tableViewPerson.tableHeaderView = self.searchBar;
- }
- /**
- viewWillAppear事件
-
- @param animated <#animated description#>
- */
- -(void)viewWillAppear:(BOOL)animated{
- if(!_filterArr){
- _filterArr=[NSMutableArray new];
- }
-
- if(!_searchArr){
- _searchArr=[NSMutableArray new];
- }
-
- [self reloadData];
- }
- /**
- dealloc事件
- */
- -(void)dealloc{
- [self cancel];
- }
- #pragma mark - 回调函数
- #pragma mark - tableveiw回调函数
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
-
- NSLog(@"cell height %f",cell.frame.size.height);
-
- return cell.frame.size.height;
-
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *CellIdentifier = @"ResponsiblePersonCell";
- ResponsiblePersonCell *cell =(ResponsiblePersonCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if(cell==nil){
- NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:CellIdentifier owner:nil options:nil];
- cell = [nibs lastObject];
- cell.backgroundColor = [UIColor clearColor];
- // cell.frame=CGRectMake(cell.frame.origin.x, cell.frame.origin.y,self.view.bounds.size.width , cell.frame.size.height);
-
- }
-
- ResponsiblePersonModel *info=self.filterArr[indexPath.row];
- cell.lblCode.text = info.staffCode;
- cell.lblName.text = info.staffName;
- cell.staffid = info.staffID;
- return cell;
-
-
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- ResponsiblePersonModel *info=self.filterArr[indexPath.row];
- if ([self.respDelegate respondsToSelector:@selector(updateResponsiblePerson:)]) {
- [self.respDelegate updateResponsiblePerson:info];
- }
-
- [self.navigationController popViewControllerAnimated:YES];
-
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return _filterArr.count;
- }
- #pragma mark - 数据回调函数
- #pragma mark searchbar回调
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
- {
- [self addCancelButton];
- return YES;
- }
- - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
- return YES;
- }
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- {
-
- if ([searchText isEqualToString:@""]) {
- self.filterArr = _searchArr;
- [self.tableViewPerson reloadData];
- return;
- }
-
- NSString *keyName = @"name";
- //< 模糊查找
- NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", keyName, searchText];
- //< 精确查找
- // NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K == %@", keyName, searchText];
-
- NSLog(@"predicate %@",predicateString);
-
- NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_searchArr filteredArrayUsingPredicate:predicateString]];
-
- self.filterArr = filteredArray;
- [self changeArrToModel:_filterArr];
- [self.tableViewPerson reloadData];
- }
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
- [searchBar resignFirstResponder];
- [self cancelSearch];
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [_searchBar resignFirstResponder];
- [self cancelSearch];
- }
- #pragma mark - 私有函数
- /**
- 进度条隐藏
- */
- - (void)cancel {
- [self stopLoading];
- }
- /**
- 返回事件
- */
- -(void)sGotoBack
- {
- [self dismissViewControllerAnimated:YES completion:nil];
- [self.navigationController popViewControllerAnimated:YES];
- }
- /**
- 数据加载
- */
- -(void)reloadData
- {
- [self.tableViewPerson reloadData ];
- }
- /**
- 取消按钮
- */
- -(void)addCancelButton
- {
- //添加取消按钮
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
- [button2 addTarget:self action:@selector(cancelSearch)
- forControlEvents:UIControlEventTouchUpInside];
- button2.frame = CGRectMake(0, 0, 40, 24);
- [button2 setTitle:@"取消" forState:UIControlStateNormal];
- [button2 setTitleColor:NavBarItemColor forState:UIControlStateNormal];
- UIBarButtonItem *menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:button2];
- self.navigationItem.rightBarButtonItem = menuButton2;
- }
- /**
- 查询取消
- */
- -(void)cancelSearch
- {
- [_searchBar resignFirstResponder];
- [self removeCancel];
- }
- /**
- 取消隐藏
- */
- -(void) removeCancel
- {
- self.navigationItem.rightBarButtonItem = nil;
- }
- /**
- 数据model
-
- @param arr <#arr description#>
- */
- -(void)changeArrToModel:(NSArray* )arr{
-
- if(arr!=nil){
-
- }
-
- }
- @end
|