zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
//  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