//
|
// PBModelSearchController.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2020/7/31.
|
// Copyright © 2020 ProBIM. All rights reserved.
|
//
|
|
#import "PBModelSearchController.h"
|
#import "PBModelsTableViewCell.h"
|
#import "PBProjectModel.h"
|
#import "PBModelsModel.h"
|
#import "PBLoadModelDisplayController.h"
|
static NSString *const cellID = @"cellID";
|
@interface PBModelSearchController ()<UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource>
|
@property (nonatomic, strong) UITableView *tableView;
|
@property (nonatomic, strong) NSArray *searchData;
|
@property (nonatomic, strong) UISearchBar *searchBar;
|
@property (nonatomic, weak) UIButton *cancelBtn;
|
@end
|
|
@implementation PBModelSearchController
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
[self setupNav];
|
[self setupUI];
|
// [self loadModelWith:@""];
|
}
|
- (void)loadModelWith:(NSString *)keyword {
|
[[PBNetworkTools sharedTools] RequestGetProjectAllModelsWithProjectID:_projectModel.bimcomposerid andKeyword:@"" andCallBack:^(NSURLSessionDataTask *task, id response, NSError *error) {
|
if (error) {
|
NSLog(@"%@",error);
|
[YJProgressHUD showMessage:@"加载失败" inView:self.view];
|
return;
|
}
|
[YJProgressHUD hide];
|
NSString *str = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
|
str = [str stringByReplacingOccurrencesOfString:@"\\" withString:@""];
|
NSMutableString *mString = [NSMutableString stringWithString:str];
|
[mString deleteCharactersInRange:NSMakeRange(0, 1)];
|
[mString deleteCharactersInRange:NSMakeRange(mString.length-1, 1)];
|
self.searchData = [NSArray yy_modelArrayWithClass:[PBModelsModel class] json:mString.copy];
|
[self.tableView reloadData];
|
}];
|
}
|
- (void)setupNav {
|
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
|
self.view.backgroundColor = [UIColor whiteColor];
|
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"whileNav"] forBarMetrics:UIBarMetricsDefault];
|
self.searchBar = [[UISearchBar alloc] init];
|
self.searchBar.placeholder = @"请输入模型名称";
|
self.searchBar.delegate = self;
|
self.searchBar.returnKeyType=UIReturnKeySearch;
|
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
|
self.navigationItem.titleView = self.searchBar;
|
[self.searchBar setShowsCancelButton:YES];
|
UIButton *cancelBtn = [self.searchBar valueForKey:@"cancelButton"];
|
self.cancelBtn = cancelBtn;
|
self.navigationItem.hidesBackButton = YES;
|
|
}
|
- (void)setupUI {
|
self.view.backgroundColor = [UIColor whiteColor];
|
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
|
self.tableView.rowHeight = 100;
|
[self.tableView registerClass:[PBModelsTableViewCell class] forCellReuseIdentifier:cellID];
|
self.tableView.delegate = self;
|
self.tableView.dataSource = self;
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
[self.view addSubview:self.tableView];
|
}
|
#pragma mark - UISearchBarDelegate
|
- (void)searchBarCancelButtonClicked:(UISearchBar*)searchBar{
|
[self.searchBar resignFirstResponder];
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
|
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
|
[self.searchBar resignFirstResponder];
|
[self loadModelWith:searchBar.text];
|
}
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
return self.searchData.count;
|
}
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
PBModelsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
|
PBModelsModel *model = self.searchData[indexPath.row];
|
cell.modelsModel = model;
|
return cell;
|
}
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
PBLoadModelDisplayController *modelDisplayVC = [[PBLoadModelDisplayController alloc] init];
|
modelDisplayVC.hidesBottomBarWhenPushed = YES;
|
modelDisplayVC.projectModel = self.projectModel;
|
modelDisplayVC.projectIID = self.projectModel.bimcomposerid;
|
NSArray *arr = self.searchData[indexPath.section];
|
PBModelsModel *modelsModel = arr[indexPath.row];
|
modelDisplayVC.modelID = modelsModel.ID;
|
[self.navigationController pushViewController:modelDisplayVC animated:YES];
|
}
|
- (void)setProjectModel:(PBProjectModel *)projectModel {
|
_projectModel = projectModel;
|
}
|
/*
|
#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
|