// // PBDocSearchController.m // IphoneBIMe // // Created by zjf on 2018/8/3. // Copyright © 2018年 ProBIM. All rights reserved. // #import "PBDocSearchController.h" @interface PBDocSearchController () @property (nonatomic, strong) UISearchBar *searchBar; @property (nonatomic, strong) UIButton *maskBtn; @end @implementation PBDocSearchController - (void)viewDidLoad { [super viewDidLoad]; [self setupNav]; } - (void)setupNav { self.view.backgroundColor = [UIColor z_colorWithR:229 G:229 B:229]; self.navigationItem.hidesBackButton = YES; self.searchBar = [[UISearchBar alloc] init]; self.searchBar.searchBarStyle = UISearchBarStyleMinimal; self.searchBar.placeholder = @"搜索项目文档"; self.searchBar.delegate = self; self.navigationItem.titleView = self.searchBar; [self.searchBar becomeFirstResponder]; UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(cancelAction)]; self.navigationItem.rightBarButtonItem = cancelItem; } - (void)cancelAction { [self.searchBar resignFirstResponder]; [self dismissViewControllerAnimated:YES completion:nil]; } #pragma mark - UISearchBarDelegate - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { NSString *search = [searchBar.text stringByReplacingOccurrencesOfString:@" " withString:@""]; if ([search isEqualToString:@""]){ return; } [self loadDocListWithLikeName:searchBar.text]; [self.searchBar resignFirstResponder]; } //- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ // [self loadDocListWithLikeName:searchBar.text]; //} - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { [self.view addSubview:self.maskBtn]; return YES; } - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { [self.maskBtn removeFromSuperview]; } - (void)loadDocListWithLikeName:(NSString *)likeName { if ([likeName isEqualToString:@""]) { self.docList = nil; [self.tableView reloadData]; return; } [[PBNetworkTools sharedTools] RequestDocSearchWithProjectID:self.projectModel.bimcomposerid andLikeName:likeName andNormalOrDrawings:@"Normal" andRoleId:@"" andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) { if (error) { NSLog(@"%@",error); return; } NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; NSArray*arr = [NSArray yy_modelArrayWithClass:[PBDocModel class] json:str]; self.docList = arr.mutableCopy; [self.tableView reloadData]; if (self.docList.count == 0) { self.promptView.hidden = NO; }else { self.promptView.hidden = YES; } }]; } - (UIButton *)maskBtn { if (_maskBtn == nil) { _maskBtn = [[UIButton alloc] initWithFrame:self.view.bounds]; _maskBtn.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2]; [_maskBtn addTarget:self action:@selector(cancelMaskBtn) forControlEvents:UIControlEventTouchUpInside]; } return _maskBtn; } - (void)cancelMaskBtn { [self.searchBar resignFirstResponder]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath]; // Configure the cell... return cell; } */ /* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ /* // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } } */ /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end