| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- //
- // IDAndNameViewController.m
- // IBOSSmini
- //
- // Created by apple on 2017/5/31.
- // Copyright © 2017年 elongtian. All rights reserved.
- //
- #import "BaseIDAndNameViewController.h"
- #import "BaseIDAndNameModel.h"
- @interface BaseIDAndNameViewController ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>
- @property(nonatomic,strong) UISearchBar *searchBar;
- @property(nonatomic,strong) UITableView *tableView;
- @end
- @implementation BaseIDAndNameViewController
- //zhushi
- #pragma mark - 公共函数
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationItem.title=@"品牌列表";
- //是否是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(goBack)
- 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(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
-
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- [self.navigationController setNavigationBarHidden:NO];
-
- }
-
- _tableView=[UITableView new];
- _tableView.delegate=self;
- _tableView.dataSource=self;
-
- //是否是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];
- //搜索框
- _searchBar=[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
- _searchBar.delegate = self;
- self.tableView.tableHeaderView=_searchBar;
- }
- /**
- didReceiveMemoryWarning
- */
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- /**
- viewWillAppear
-
- @param animated <#animated description#>
- */
- - (void)viewWillAppear:(BOOL)animated
- {
- [self.tableView reloadData];
- }
- /**
- dealloc
- */
- - (void)dealloc
- {
- [self cancel];
- }
- #pragma mark - 委托回调函数
- #pragma mark - tableView回调
- /**
- Sections
- @param tableView <#tableView description#>
- @return <#return value description#>
- */
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- /**
- Sections的行数
- @param tableView <#tableView description#>
- @param section <#section description#>
- @return <#return value description#>
- */
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return _filterArr.count;
- }
- /**
- 单元格cell
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- @return <#return value description#>
- */
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
- if(cell==nil)
- {
- cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
- BaseIDAndNameModel *model = _filterArr[indexPath.row];
- // cell.tag=[[dic objectForKey:@"BrandID"] intValue];
- cell.textLabel.text = model.name;
- cell.textLabel.textAlignment = NSTextAlignmentCenter;
- cell.textLabel.font = [UIFont systemFontOfSize:SubControllerListFontOfSize];
- return cell;
- }
- /**
- 单元格点击事件
- @param tableView <#tableView description#>
- @param indexPath <#indexPath description#>
- */
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- BaseIDAndNameModel *model = _filterArr[indexPath.row];
-
- 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];
- }
- }
- #pragma mark searchbar回调
- /**
- 查询取消按钮添加
- @param searchBar <#searchBar description#>
- @return <#return value description#>
- */
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
- {
- [self addCancelButton];
- return YES;
- }
- /**
- shouldChangeTextInRange
- @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.filterArr = _searchArr;
- [_tableView 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;
- [_tableView reloadData];
- }
- /**
- 点击事件
- @param searchBar <#searchBar description#>
- */
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- {
- [searchBar resignFirstResponder];
- [self cancelSearch];
- }
- /**
- scrollViewWillBeginDragging
- @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)goBack
- {
- //是否是dismissViewController
- if (_isPresentViewFlg) {
- [self dismissViewControllerAnimated:YES completion:nil];
- }else{
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- @end
|