| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- //
- // ResponsiblePersonViewController.m
- // IBOSS
- //
- // Created by apple on 2017/5/27.
- // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
- //
- // 功能描述:责任人控制器
- //
- #import "ResponsiblePersonViewController.h"
- #import "ResponsiblePersonCell.h"
- @interface ResponsiblePersonViewController ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>
- /**
- 查询bar
- */
- @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,45,22);
-
- 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(!_arrFilter){
- _arrFilter = [[NSMutableArray alloc]init];
- }
- if(!_arrSearch){
- _arrSearch = [[NSMutableArray alloc]init];
- }
- [self reloadData];
- }
- /**
- dealloc事件
- */
- - (void)dealloc{
- [self cancel];
- }
- #pragma mark - 回调函数
- #pragma mark - tableveiw回调函数
- /**
- 单元格高度
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
- return cell.frame.size.height;
- }
- /**
- 单元格
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (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];
- }
-
- ResponsiblePersonModel *info=self.arrFilter[indexPath.row];
- cell.lblCode.text = info.staffCode;
- cell.lblName.text = info.staffName;
- cell.staffid = info.staffID;
- return cell;
- }
- /**
- 单元格点击事件
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- */
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- ResponsiblePersonModel *info = self.arrFilter[indexPath.row];
- if ([self.respDelegate respondsToSelector:@selector(updateResponsiblePerson:)]) {
- [self.respDelegate updateResponsiblePerson:info];
- }
-
- [self.navigationController popViewControllerAnimated:YES];
-
- }
- /**
- 数据源
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.arrFilter.count;
- }
- #pragma mark - 数据回调函数
- #pragma mark searchbar回调
- /**
- 开始编辑
- @param searchBar <#searchBar description#>
- @return <#return value description#>
- */
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
- {
- [self addCancelButton];
- return YES;
- }
- /**
- 如何实现对UITextField ,UITextView等输入框的 字数限制
- @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;
- }
- /**
- textDidChange回调
- @param searchBar <#searchBar description#>
- @param searchText <#searchText description#>
- */
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- {
-
- if ([searchText isEqualToString:@""]) {
- self.arrFilter = _arrSearch;
- [self.tableViewPerson reloadData];
- return;
- }
-
- NSString *keyName = @"name";
- //< 模糊查找
- NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", keyName, searchText];
- NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearch filteredArrayUsingPredicate:predicateString]];
-
- self.arrFilter = filteredArray;
- [self changeArrToModel:self.arrFilter];
- [self.tableViewPerson 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)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
|