SearchBaseVC.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. //
  2. // SearchBaseVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/1/1.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "SearchBaseVC.h"
  9. #import "SearchCell.h"
  10. #import "DrawerView.h"
  11. #import "TabBarController.h"
  12. @interface SearchBaseVC ()<UISearchBarDelegate,UICollectionViewDelegate,UICollectionViewDataSource,InfoSearchViewDelegate>
  13. //@property (strong, nonatomic) UISearchBar * searchBar;
  14. //@property (strong, nonatomic) UIView * searchV;
  15. //@property (strong, nonatomic) UIButton * backBtn;
  16. //@property (strong, nonatomic) UIButton * menuBtn;
  17. //@property (strong, nonatomic) UIView * navBarV;
  18. @property (nonatomic, strong) NSMutableArray * dataDistoryArray;
  19. @property (strong,nonatomic) DrawerView *drawerView;
  20. @end
  21. @implementation SearchBaseVC
  22. - (InfoSearchView *)topNavSearch {
  23. if (!_topNavSearch) {
  24. _topNavSearch = [[InfoSearchView alloc] initWithFrame:CGRectMake(0, (IS_IPHONEX?40:20), kGXScreenWidth, 45) type:InfoSearchViewTypeDefault];
  25. _topNavSearch.delegate = self;
  26. WS(weakSelf);
  27. _topNavSearch.backBlock = ^{
  28. if (weakSelf.collectionView.isHidden) {
  29. weakSelf.collectionView.hidden = NO;
  30. weakSelf.noDataView.hidden = YES;
  31. weakSelf.tableView.hidden = YES;
  32. weakSelf.IsBViewHidden = @"YES";
  33. }else{
  34. [weakSelf.navigationController popViewControllerAnimated:YES];
  35. }
  36. };
  37. _topNavSearch.cancelBlock = ^{
  38. if (weakSelf.cancelBlock) {
  39. weakSelf.cancelBlock();
  40. }
  41. weakSelf.collectionView.hidden = NO;
  42. weakSelf.noDataView.hidden = YES;
  43. weakSelf.tableView.hidden = YES;
  44. };
  45. // self.topNavSearch.backBlock = ^{
  46. // if (weakSelf.cancelBtn.isHidden) {
  47. // [weakSelf.navigationController popViewControllerAnimated:YES];
  48. // }else{
  49. // weakSelf.collectionView.hidden = NO;
  50. // weakSelf.noDataView.hidden = YES;
  51. // weakSelf.tableView.hidden = YES;
  52. // // [weakSelf upCanCelBtnConstraits];
  53. // }
  54. // };
  55. // self.topNavSearch.cancelBlock = ^{
  56. // // weakSelf.searchBar.text = @"";
  57. // weakSelf.collectionView.hidden = NO;
  58. // weakSelf.noDataView.hidden = YES;
  59. // weakSelf.tableView.hidden = YES;
  60. // // [weakSelf upCanCelBtnConstraits];
  61. // };
  62. _topNavSearch.menuBlock = ^{
  63. [weakSelf.view endEditing:YES];
  64. [[UtilsTools getWindow] addSubview:weakSelf.drawerView];
  65. weakSelf.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
  66. if (![weakSelf.tabBarController isKindOfClass:[TabBarController class]]) {
  67. [TabBarController sharedTabBarController].tabBar.hidden = NO;
  68. [weakSelf.tabBarController.navigationController popViewControllerAnimated:NO];
  69. }
  70. if ([weakSelf.navigationController.viewControllers count] > 1) {
  71. [weakSelf.navigationController popToRootViewControllerAnimated:NO];
  72. }
  73. switch (indexPath.section) {
  74. case 0:
  75. {
  76. [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
  77. }
  78. break;
  79. case 1:
  80. {
  81. switch (indexPath.row) {
  82. case 0:
  83. {
  84. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  85. }
  86. break;
  87. case 1:
  88. {
  89. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  90. }
  91. break;
  92. default:
  93. {
  94. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  95. }
  96. break;
  97. }
  98. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  99. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
  100. });
  101. }
  102. break;
  103. default:
  104. {
  105. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  106. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  107. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(4 + indexPath.row)}];
  108. });
  109. }
  110. break;
  111. }
  112. };
  113. weakSelf.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);// - kNavigationHeight
  114. };
  115. }
  116. return _topNavSearch;
  117. }
  118. -(DrawerView *)drawerView{
  119. if(!_drawerView){
  120. _drawerView = [[DrawerView alloc] init];
  121. }
  122. return _drawerView;
  123. }
  124. - (UIView *)noDataView
  125. {
  126. if (!_noDataView) {
  127. _noDataView = [UIView new];
  128. _noDataView.hidden = YES;
  129. _noDataView.backgroundColor = [UIColor whiteColor];
  130. }
  131. return _noDataView;
  132. }
  133. - (UILabel *)noDataL
  134. {
  135. if (!_noDataL) {
  136. _noDataL = [UILabel new];
  137. _noDataL.textColor = UIColorHex(#BBBBBB);
  138. _noDataL.font = [UIFont systemFontOfSize:15];
  139. }
  140. return _noDataL;
  141. }
  142. - (UIButton *)cancelBtn
  143. {
  144. if (!_cancelBtn) {
  145. _cancelBtn = [UIButton new];
  146. [_cancelBtn setAttributedTitle:[[NSMutableAttributedString alloc] initWithString:@"取消" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 15],NSForegroundColorAttributeName: UIColorHex(#3979D3)}] forState:UIControlStateNormal];
  147. }
  148. return _cancelBtn;
  149. }
  150. //- (UIButton *)backBtn
  151. //{
  152. // if (!_backBtn) {
  153. // _backBtn = [UIButton new];
  154. // [_backBtn setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
  155. // }
  156. // return _backBtn;
  157. //}
  158. //- (UIButton *)menuBtn
  159. //{
  160. // if (!_menuBtn) {
  161. // _menuBtn = [UIButton new];
  162. // [_menuBtn setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
  163. // }
  164. // return _menuBtn;
  165. //}
  166. - (UILabel *)lineL
  167. {
  168. if (!_lineL) {
  169. _lineL = [UILabel new];
  170. _lineL.backgroundColor = LINEBGCOLOR;
  171. }
  172. return _lineL;
  173. }
  174. //- (UIView *)navBarV
  175. //{
  176. // if (!_navBarV) {
  177. // _navBarV = [UIView new];
  178. // _navBarV.backgroundColor = [UIColor whiteColor];
  179. // }
  180. // return _navBarV;
  181. //}
  182. //- (UISearchBar *)searchBar
  183. //{
  184. // if (!_searchBar) {
  185. // _searchBar = [UISearchBar new];
  186. // }
  187. // return _searchBar;
  188. //}
  189. - (UICollectionView *)collectionView
  190. {
  191. if (!_collectionView) {
  192. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  193. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  194. layout.sectionInset = UIEdgeInsetsMake(0, 15, 15, 15);
  195. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  196. [_collectionView registerClass:[SearchCell class] forCellWithReuseIdentifier:@"cellId"];
  197. }
  198. return _collectionView;
  199. }
  200. - (UITableView *)tableView
  201. {
  202. if (!_tableView) {
  203. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  204. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  205. }
  206. return _tableView;
  207. }
  208. - (void)setHistorySearchType:(HistorySearchType)historySearchType
  209. {
  210. _historySearchType = historySearchType;
  211. self.dataDistoryArray = [[_TDFileStorage loadHistorySearchBySearchType:_historySearchType] mutableCopy];
  212. }
  213. - (void)viewDidLoad {
  214. [super viewDidLoad];
  215. self.fd_prefersNavigationBarHidden = YES;
  216. [self setCusView];
  217. self.collectionView.hidden = NO;
  218. self.tableView.hidden = YES;
  219. self.collectionView.delegate = self;
  220. self.collectionView.dataSource = self;
  221. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headReusableView"];
  222. self.collectionView.backgroundColor = [UIColor whiteColor];
  223. self.view.backgroundColor = RGB(255, 255, 255);
  224. // [self.cancelBtn setAction:^{
  225. // weakSelf.searchBar.text = @"";
  226. // weakSelf.collectionView.hidden = NO;
  227. // weakSelf.noDataView.hidden = YES;
  228. // weakSelf.tableView.hidden = YES;
  229. // [weakSelf upCanCelBtnConstraits];
  230. // }];
  231. // [self.searchBar becomeFirstResponder];
  232. self.IsBViewHidden = @"";
  233. }
  234. - (void)setCusView
  235. {
  236. // [self.view addSubview:self.navBarV];
  237. // [self.navBarV mas_makeConstraints:^(MASConstraintMaker *make) {
  238. // make.top.left.right.mas_equalTo(self.view);
  239. // make.height.offset(IS_IPHONEX ? 84:64);
  240. // }];
  241. // [self.navBarV addSubview:self.backBtn];
  242. // [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  243. // make.left.bottom.mas_equalTo(self.navBarV);
  244. // make.size.mas_offset(CGSizeMake(50, 44));
  245. // }];
  246. // [self.navBarV addSubview:self.menuBtn];
  247. // [self.menuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  248. // make.bottom.mas_equalTo(self.navBarV);
  249. // make.left.mas_equalTo(self.backBtn.mas_right);
  250. // make.size.mas_offset(CGSizeMake(50, 44));
  251. // }];
  252. // [self.navBarV addSubview:self.cancelBtn];
  253. // [self upCanCelBtnConstraits];
  254. // [self.navBarV addSubview:self.searchBar];
  255. // [self.searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
  256. // make.left.mas_equalTo(self.backBtn.mas_right);
  257. // make.centerY.mas_equalTo(self.backBtn);
  258. // make.height.mas_offset(32);
  259. // make.right.mas_equalTo(self.cancelBtn.mas_left).offset(-15);
  260. // }];
  261. [self.view addSubview:self.topNavSearch];
  262. if (self.IsAddUser) {
  263. CGRect rect = self.topNavSearch.searchBar.frame;
  264. CGFloat w = rect.size.width - 60;
  265. rect.size.width = w;
  266. self.topNavSearch.searchBar.frame = rect;
  267. [self.topNavSearch addSubview:self.cancelBtn];
  268. [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  269. make.left.mas_equalTo(self.topNavSearch.searchBar.mas_right).offset(5);
  270. make.top.bottom.mas_equalTo(self.topNavSearch.searchBar);
  271. make.width.mas_offset(55);
  272. }];
  273. }
  274. [self.view addSubview:self.lineL];
  275. [self.lineL mas_makeConstraints:^(MASConstraintMaker *make) {
  276. make.left.right.mas_equalTo(self.view);
  277. make.top.mas_equalTo(self.topNavSearch.mas_bottom);
  278. make.height.mas_offset(0.5);
  279. }];
  280. [self.view addSubview:self.collectionView];
  281. [self.view addSubview:self.tableView];
  282. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  283. make.top.mas_equalTo(self.lineL.mas_bottom);
  284. make.left.right.mas_equalTo(self.view);
  285. if (@available(iOS 11.0, *)) {
  286. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  287. } else {
  288. make.bottom.equalTo(self.view.mas_bottom);
  289. }
  290. }];
  291. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  292. make.top.mas_equalTo(self.lineL.mas_bottom);
  293. make.left.right.mas_equalTo(self.view);
  294. if (@available(iOS 11.0, *)) {
  295. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  296. } else {
  297. make.bottom.equalTo(self.view.mas_bottom);
  298. }
  299. }];
  300. [self.view addSubview:self.noDataView];
  301. self.noDataView.hidden = YES;
  302. [self.noDataView mas_makeConstraints:^(MASConstraintMaker *make) {
  303. make.top.mas_equalTo(self.lineL.mas_bottom);
  304. make.left.right.mas_equalTo(self.view);
  305. if (@available(iOS 11.0, *)) {
  306. make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  307. } else {
  308. make.bottom.equalTo(self.view.mas_bottom);
  309. }
  310. }];
  311. [self.noDataView addSubview:self.noDataL];
  312. [self.noDataL mas_makeConstraints:^(MASConstraintMaker *make) {
  313. make.center.mas_equalTo(self.noDataView);
  314. }];
  315. // _searchBar.backgroundImage = [UtilsTools imageWithColor:[UIColor clearColor] size:_searchBar.bounds.size];
  316. //
  317. // UIImage* clearImg = [UtilsTools imageWithColor:[UIColor clearColor] andHeight:44.0f];
  318. // [_searchBar setBackgroundImage:clearImg];
  319. // [_searchBar setSearchFieldBackgroundImage:clearImg forState:UIControlStateNormal];
  320. // [_searchBar setBackgroundColor:[UIColor clearColor]];
  321. //
  322. // [_searchV setBackgroundColor:[UIColor whiteColor]];
  323. // [_searchV setRadius:4 borderColor:RGB(204, 204, 204) borderWidth:.5];
  324. // self.searchBar.delegate = self;
  325. //
  326. // if ([UIDevice currentDevice].systemVersion.floatValue >= 13.0) {
  327. // self.searchBar.searchTextField.font = [UIFont systemFontOfSize:14.0];
  328. // if (!self.searchBar.searchTextField.placeholder) {
  329. // self.searchBar.searchTextField.placeholder = @"搜索";
  330. // }
  331. // NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:self.searchBar.searchTextField.placeholder attributes: @{NSForegroundColorAttributeName:RGB(153, 153, 153), NSFontAttributeName:self.searchBar.searchTextField.font}];
  332. // self.searchBar.searchTextField.attributedPlaceholder = attrString;
  333. // }else{
  334. // for (UIView *view in self.searchBar.subviews.lastObject.subviews) {
  335. // if([view isKindOfClass:NSClassFromString(@"UISearchBarTextField")]) {
  336. // UITextField *textField = (UITextField *)view;
  337. // //设置输入框的背景颜色
  338. // textField.clipsToBounds = YES;
  339. // //设置输入字体颜色
  340. // textField.textColor = [UIColor blackColor];
  341. // //设置默认文字颜色
  342. // textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@" 搜索" attributes:@{NSForegroundColorAttributeName:[UIColor hexStringToColor:@"999999"]}];
  343. // textField.font = [UIFont systemFontOfSize:14];
  344. // for (UIView * subView in view.subviews) {
  345. // if ([subView isKindOfClass:NSClassFromString(@"UIImageView")]) {
  346. // UIImageView * imageV = (UIImageView *)subView;
  347. // imageV.image = IMG(@"searchIcon");
  348. // }
  349. // }
  350. // }
  351. // }
  352. // }
  353. }
  354. - (NSMutableArray *)dataDistoryArray
  355. {
  356. if (!_dataDistoryArray) {
  357. _dataDistoryArray = [NSMutableArray array];
  358. }
  359. return _dataDistoryArray;
  360. }
  361. /**********************************************************************/
  362. #pragma mark -UICollectionViewDataSource
  363. /**********************************************************************/
  364. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  365. if (self.dataDistoryArray.count == 0) {
  366. return 0;
  367. }
  368. return 1;
  369. }
  370. /**********************************************************************/
  371. #pragma mark -GHRefreshCollectionView的section的Count
  372. /**********************************************************************/
  373. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  374. return self.dataDistoryArray.count;
  375. }
  376. #pragma mark - UICollectionViewDelegate
  377. - (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
  378. SearchCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
  379. cell.titleL.text = [self.dataDistoryArray objectAtIndex:indexPath.row];
  380. return cell;
  381. }
  382. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  383. NSString * name = [self.dataDistoryArray objectAtIndex:indexPath.row];
  384. UILabel * label = [UILabel new];
  385. label.text = name;
  386. label.font = Kfont(13);
  387. CGFloat W = [label sizeThatFits:CGSizeMake(MAXFLOAT, 25)].width;
  388. return CGSizeMake(name.length > 0 ? (W + 22) : 0, 25);
  389. }
  390. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  391. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  392. [self selectIndexText:[self.dataDistoryArray objectAtIndex:indexPath.row]];
  393. }
  394. //footer的size
  395. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  396. {
  397. return CGSizeMake(0, 0);
  398. }
  399. //header的size
  400. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  401. {
  402. return CGSizeMake(SCREEN_WIDTH, 44);
  403. }
  404. //设置每个item水平间距
  405. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  406. {
  407. return 10.f;
  408. }
  409. //设置每个item垂直间距
  410. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  411. {
  412. return 10.f;
  413. }
  414. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  415. if([kind isEqualToString:UICollectionElementKindSectionHeader]){
  416. UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headReusableView" forIndexPath:indexPath];
  417. [headerView removeAllSubviews];
  418. UILabel *label = [[UILabel alloc] init];
  419. [headerView addSubview:label];
  420. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  421. make.centerY.equalTo(headerView);
  422. make.left.equalTo(@(15));
  423. }];
  424. label.text = @"最近搜索";
  425. label.font = [UIFont systemFontOfSize:16];
  426. label.textColor = UIColorHex(#333333);
  427. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  428. [headerView addSubview:closeBtn];
  429. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  430. make.centerY.equalTo(headerView);
  431. make.right.equalTo(@(-15));
  432. }];
  433. [closeBtn setImage:IMG(@"mail_clear_Icon") forState:UIControlStateNormal];
  434. WS(weakSelf);
  435. [closeBtn setAction:^{
  436. [weakSelf.dataDistoryArray removeAllObjects];
  437. [_TDFileStorage saveHistorySearchBySearchType:self.historySearchType WithArr:@[]];
  438. [weakSelf.dataDistoryArray addObject:@""];
  439. [weakSelf.collectionView reloadData];
  440. }];
  441. headerView.backgroundColor = [UIColor whiteColor];
  442. return headerView;
  443. }
  444. return nil;
  445. }
  446. - (void)searchButtonAction:(UISearchBar *)searchBar {
  447. if (searchBar.text.length > 0) {
  448. [self selectIndexText:searchBar.text];
  449. }
  450. }
  451. - (void)selectIndexText:(NSString *)text
  452. {
  453. self.topNavSearch.searchBar.text = text;
  454. self.searchText = text;
  455. self.tableView.hidden = NO;
  456. self.collectionView.hidden = YES;
  457. [self checkRepeatString:text];
  458. [self.view endEditing:YES];
  459. if (self.searchBlock) {
  460. self.searchBlock(text);
  461. }
  462. }
  463. - (void)checkRepeatString:(NSString *)string {
  464. for (NSString *cache in self.dataDistoryArray) {
  465. if ([cache isEqualToString:string]) {
  466. return;
  467. }
  468. }
  469. [self.dataDistoryArray insertObject:string atIndex:0];
  470. [_TDFileStorage saveHistorySearchBySearchType:self.historySearchType WithArr:self.dataDistoryArray];
  471. [self.collectionView reloadData];
  472. }
  473. /**********************************************************************/
  474. #pragma mark - UISearchBarDelegate
  475. /**********************************************************************/
  476. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  477. }
  478. - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
  479. {
  480. if (searchBar.text.length > 0) {
  481. [self selectIndexText:searchBar.text];
  482. [self checkRepeatString:searchBar.text];
  483. }
  484. }
  485. - (void)textDidChange:(NSString *)text {
  486. if (text.length > 0) {
  487. [self selectIndexText:text];
  488. }
  489. }
  490. //- (void)searchBarTextDidBeginEditing:(UISearchBar *) searchBar{
  491. // UITextField *searchBarTextField = nil;
  492. // NSArray *views = ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) ? searchBar.subviews : [[searchBar.subviews objectAtIndex:0] subviews];
  493. //
  494. // for (UIView *subview in views){
  495. // if ([subview isKindOfClass:[UITextField class]]){
  496. // searchBarTextField = (UITextField *)subview;
  497. // break;
  498. // }
  499. // }
  500. // searchBarTextField.enablesReturnKeyAutomatically = NO;
  501. //}
  502. //- (void)showCancelBtn
  503. //{
  504. // if (self.cancelBtn.hidden) {
  505. // self.cancelBtn.hidden = NO;
  506. // [self.cancelBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  507. // make.right.mas_equalTo(self.navBarV.mas_right).offset(-15);
  508. // make.centerY.mas_equalTo(self.backBtn);
  509. // }];
  510. // }
  511. //}
  512. //- (void)upCanCelBtnConstraits
  513. //{
  514. // self.cancelBtn.hidden = YES;
  515. // [self.cancelBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  516. // make.right.mas_equalTo(self.navBarV.mas_right);
  517. // make.centerY.mas_equalTo(self.backBtn);
  518. // make.width.mas_offset(0);
  519. // }];
  520. //}
  521. //- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope{
  522. // NSLog(@"%@1",searchBar.text);
  523. //}
  524. @end