SearchBaseVC.m 22 KB

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