From f86647c644b10a03300906aac377505ad1c24c98 Mon Sep 17 00:00:00 2001
From: zjf <zhangjf@probim.com.cn>
Date: Mon, 13 Mar 2023 13:33:04 +0800
Subject: [PATCH] 项目搜索历史标签 及 现场 新增标签更换库  collection view 添加背景颜色 cell修改样式

---
 IphoneBIMe/IphoneBIMe/Classes/ProjectList/Views/PBProjectSearchView.m |   54 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/IphoneBIMe/IphoneBIMe/Classes/ProjectList/Views/PBProjectSearchView.m b/IphoneBIMe/IphoneBIMe/Classes/ProjectList/Views/PBProjectSearchView.m
index bb0ed23..f5bc298 100644
--- a/IphoneBIMe/IphoneBIMe/Classes/ProjectList/Views/PBProjectSearchView.m
+++ b/IphoneBIMe/IphoneBIMe/Classes/ProjectList/Views/PBProjectSearchView.m
@@ -7,15 +7,18 @@
 //
 
 #import "PBProjectSearchView.h"
-#import "MSSAutoresizeLabelFlow.h"
 #import "PBProjectTableViewCell.h"
 #import "PBProjectModel.h"
 #import "PBTabBarController.h"
-@interface PBProjectSearchView()<UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate>
-@property(nonatomic,strong)MSSAutoresizeLabelFlow *historicalRecordV;
+#import "LBKeyWordLayout.h"
+#import "KeyWordCell.h"
+@interface PBProjectSearchView()<UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
 @property (nonatomic, strong) UITableView *tableView;
 @property (nonatomic, strong) NSArray *dataList;
 @property (nonatomic, weak) UISearchBar *searchBar;
+@property (nonatomic, strong) UICollectionView *collectionView;
+@property (strong, nonatomic) LBKeyWordLayout *layout;
+@property (strong, nonatomic) NSArray *items;
 @end
 @implementation PBProjectSearchView
 - (instancetype)initWithFrame:(CGRect)frame {
@@ -87,13 +90,21 @@
         make.right.equalTo(self).offset(-18);
         make.size.mas_equalTo(CGSizeMake(24, 24));
     }];
-    NSArray *array = [self readSearchHistory];
-    _historicalRecordV = [[MSSAutoresizeLabelFlow alloc] initWithFrame:CGRectMake(0, 150, PBScreenWidth, 200) titles:array selectedHandler:^(NSUInteger index, NSString *title) {
-        NSLog(@"%@",title);
-        self.searchBar.text = title;
-        [self searchActionWithTitle:title];
-    }];
-    [self addSubview:_historicalRecordV];
+    self.items = [self readSearchHistory];
+//    _historicalRecordV = [[MSSAutoresizeLabelFlow alloc] initWithFrame:CGRectMake(0, 150, PBScreenWidth, 200) titles:array selectedHandler:^(NSUInteger index, NSString *title) {
+//        NSLog(@"%@",title);
+//        self.searchBar.text = title;
+//        [self searchActionWithTitle:title];
+//    }];
+    self.layout = [[LBKeyWordLayout alloc] init];
+    self.layout.estimatedItemSize = CGSizeMake(80, 30);
+    self.layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
+    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 150, PBScreenWidth, 400) collectionViewLayout:self.layout];
+    self.collectionView.backgroundColor = [UIColor whiteColor];
+    [self.collectionView registerClass:[KeyWordCell class] forCellWithReuseIdentifier:@"KeyWordCell"];
+    self.collectionView.delegate = self;
+    self.collectionView.dataSource = self;
+    [self addSubview:self.collectionView];
     [self addSubview:self.tableView];
     self.tableView.hidden = YES;
 }
@@ -110,7 +121,8 @@
     }
     [arrM insertObject:title atIndex:0];
     [self writeSearchHistoryWithData:arrM.copy];
-    [self.historicalRecordV reloadAllWithTitles:arrM.copy];
+    self.items = arrM.copy;
+    [self.collectionView reloadData];
 }
 - (void)backActon {
     if (self.cancelSearchBlock) {
@@ -219,7 +231,8 @@
     NSString *documentPath = [documents stringByAppendingPathComponent:@"searchHistory.plist"];
     NSFileManager *fileManager = [NSFileManager defaultManager];
     [fileManager removeItemAtPath:documentPath error:nil];
-    [self.historicalRecordV reloadAllWithTitles:@[]];
+    self.items = @[];
+    [self.collectionView reloadData];
 }
 #pragma mark - 插入本地历史记录
 - (void)writeSearchHistoryWithData:(NSArray *)history {
@@ -228,6 +241,23 @@
     NSString *documentPath = [documents stringByAppendingPathComponent:@"searchHistory.plist"];
     [history writeToFile:documentPath atomically:YES];
 }
+#pragma mark - UICollectionView
+- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
+    return self.items.count;
+}
+
+- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
+    KeyWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"KeyWordCell" forIndexPath:indexPath];
+    cell.maxWidthConstraint.constant = CGRectGetWidth(collectionView.bounds) - self.layout.sectionInset.left - self.layout.sectionInset.right - cell.layoutMargins.left - cell.layoutMargins.right - 10;
+    cell.textLabel.numberOfLines = 1;
+    cell.textLabel.text = self.items[indexPath.row];
+    return cell;
+}
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
+    self.searchBar.text = self.items[indexPath.row];
+    [self searchActionWithTitle:self.items[indexPath.row]];
+}
+
 /*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.

--
Gitblit v1.9.3