SearchBaseVC.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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 (nonatomic, strong) NSMutableArray * dataDistoryArray;
  20. @property (strong,nonatomic) DrawerView *drawerView;
  21. @property (nonatomic, strong) InfoSearchView *topNavSearch;
  22. @end
  23. @implementation SearchBaseVC
  24. - (InfoSearchView *)topNavSearch {
  25. if (!_topNavSearch) {
  26. _topNavSearch = [[InfoSearchView alloc] initWithFrame:CGRectMake(0, (IS_IPHONEX?40:20), kGXScreenWidth, 45) type:InfoSearchViewTypeDefault];
  27. _topNavSearch.delegate = self;
  28. WS(weakSelf);
  29. _topNavSearch.backBlock = ^{
  30. if (weakSelf.collectionView.isHidden) {
  31. weakSelf.collectionView.hidden = NO;
  32. weakSelf.noDataView.hidden = YES;
  33. weakSelf.tableView.hidden = YES;
  34. }else{
  35. [weakSelf.navigationController popViewControllerAnimated:YES];
  36. }
  37. };
  38. _topNavSearch.cancelBlock = ^{
  39. if (weakSelf.cancelBlock) {
  40. weakSelf.cancelBlock();
  41. }
  42. weakSelf.collectionView.hidden = NO;
  43. weakSelf.noDataView.hidden = YES;
  44. weakSelf.tableView.hidden = YES;
  45. };
  46. // self.topNavSearch.backBlock = ^{
  47. // if (weakSelf.cancelBtn.isHidden) {
  48. // [weakSelf.navigationController popViewControllerAnimated:YES];
  49. // }else{
  50. // weakSelf.collectionView.hidden = NO;
  51. // weakSelf.noDataView.hidden = YES;
  52. // weakSelf.tableView.hidden = YES;
  53. // // [weakSelf upCanCelBtnConstraits];
  54. // }
  55. // };
  56. // self.topNavSearch.cancelBlock = ^{
  57. // // weakSelf.searchBar.text = @"";
  58. // weakSelf.collectionView.hidden = NO;
  59. // weakSelf.noDataView.hidden = YES;
  60. // weakSelf.tableView.hidden = YES;
  61. // // [weakSelf upCanCelBtnConstraits];
  62. // };
  63. _topNavSearch.menuBlock = ^{
  64. [weakSelf.view endEditing:YES];
  65. [[UtilsTools getWindow] addSubview:weakSelf.drawerView];
  66. weakSelf.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
  67. if (![weakSelf.tabBarController isKindOfClass:[TabBarController class]]) {
  68. [TabBarController sharedTabBarController].tabBar.hidden = NO;
  69. [weakSelf.tabBarController.navigationController popViewControllerAnimated:NO];
  70. }
  71. if ([weakSelf.navigationController.viewControllers count] > 1) {
  72. [weakSelf.navigationController popToRootViewControllerAnimated:NO];
  73. }
  74. switch (indexPath.section) {
  75. case 0:
  76. {
  77. [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
  78. }
  79. break;
  80. case 1:
  81. {
  82. switch (indexPath.row) {
  83. case 0:
  84. {
  85. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  86. }
  87. break;
  88. case 1:
  89. {
  90. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  91. }
  92. break;
  93. default:
  94. {
  95. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  96. }
  97. break;
  98. }
  99. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  100. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
  101. });
  102. }
  103. break;
  104. default:
  105. {
  106. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  107. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  108. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(4 + indexPath.row)}];
  109. });
  110. }
  111. break;
  112. }
  113. };
  114. weakSelf.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);// - kNavigationHeight
  115. };
  116. }
  117. return _topNavSearch;
  118. }
  119. -(DrawerView *)drawerView{
  120. if(!_drawerView){
  121. _drawerView = [[DrawerView alloc] init];
  122. }
  123. return _drawerView;
  124. }
  125. - (UIView *)noDataView
  126. {
  127. if (!_noDataView) {
  128. _noDataView = [UIView new];
  129. _noDataView.hidden = YES;
  130. _noDataView.backgroundColor = [UIColor whiteColor];
  131. }
  132. return _noDataView;
  133. }
  134. - (UILabel *)noDataL
  135. {
  136. if (!_noDataL) {
  137. _noDataL = [UILabel new];
  138. _noDataL.textColor = UIColorHex(#BBBBBB);
  139. _noDataL.font = [UIFont systemFontOfSize:15];
  140. }
  141. return _noDataL;
  142. }
  143. - (UIButton *)cancelBtn
  144. {
  145. if (!_cancelBtn) {
  146. _cancelBtn = [UIButton new];
  147. [_cancelBtn setAttributedTitle:[[NSMutableAttributedString alloc] initWithString:@"取消" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 15],NSForegroundColorAttributeName: UIColorHex(#3979D3)}] forState:UIControlStateNormal];
  148. }
  149. return _cancelBtn;
  150. }
  151. //- (UIButton *)backBtn
  152. //{
  153. // if (!_backBtn) {
  154. // _backBtn = [UIButton new];
  155. // [_backBtn setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
  156. // }
  157. // return _backBtn;
  158. //}
  159. //- (UIButton *)menuBtn
  160. //{
  161. // if (!_menuBtn) {
  162. // _menuBtn = [UIButton new];
  163. // [_menuBtn setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
  164. // }
  165. // return _menuBtn;
  166. //}
  167. - (UILabel *)lineL
  168. {
  169. if (!_lineL) {
  170. _lineL = [UILabel new];
  171. _lineL.backgroundColor = LINEBGCOLOR;
  172. }
  173. return _lineL;
  174. }
  175. //- (UIView *)navBarV
  176. //{
  177. // if (!_navBarV) {
  178. // _navBarV = [UIView new];
  179. // _navBarV.backgroundColor = [UIColor whiteColor];
  180. // }
  181. // return _navBarV;
  182. //}
  183. //- (UISearchBar *)searchBar
  184. //{
  185. // if (!_searchBar) {
  186. // _searchBar = [UISearchBar new];
  187. // }
  188. // return _searchBar;
  189. //}
  190. - (UICollectionView *)collectionView
  191. {
  192. if (!_collectionView) {
  193. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  194. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  195. layout.sectionInset = UIEdgeInsetsMake(0, 15, 15, 15);
  196. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  197. [_collectionView registerClass:[SearchCell class] forCellWithReuseIdentifier:@"cellId"];
  198. }
  199. return _collectionView;
  200. }
  201. - (UITableView *)tableView
  202. {
  203. if (!_tableView) {
  204. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  205. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  206. }
  207. return _tableView;
  208. }
  209. - (void)setHistorySearchType:(HistorySearchType)historySearchType
  210. {
  211. _historySearchType = historySearchType;
  212. self.dataDistoryArray = [[_TDFileStorage loadHistorySearchBySearchType:_historySearchType] mutableCopy];
  213. }
  214. - (void)viewDidLoad {
  215. [super viewDidLoad];
  216. self.fd_prefersNavigationBarHidden = YES;
  217. [self setCusView];
  218. self.collectionView.hidden = NO;
  219. self.tableView.hidden = YES;
  220. self.collectionView.delegate = self;
  221. self.collectionView.dataSource = self;
  222. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headReusableView"];
  223. self.collectionView.backgroundColor = [UIColor whiteColor];
  224. self.view.backgroundColor = RGB(255, 255, 255);
  225. // [self.cancelBtn setAction:^{
  226. // weakSelf.searchBar.text = @"";
  227. // weakSelf.collectionView.hidden = NO;
  228. // weakSelf.noDataView.hidden = YES;
  229. // weakSelf.tableView.hidden = YES;
  230. // [weakSelf upCanCelBtnConstraits];
  231. // }];
  232. // [self.searchBar becomeFirstResponder];
  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(W + 22, 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.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.topNavSearch.searchBar.text = text;
  453. self.searchText = text;
  454. self.tableView.hidden = NO;
  455. self.collectionView.hidden = YES;
  456. [self checkRepeatString:text];
  457. [self.view endEditing:YES];
  458. if (self.searchBlock) {
  459. self.searchBlock(text);
  460. }
  461. }
  462. - (void)checkRepeatString:(NSString *)string {
  463. for (NSString *cache in self.dataDistoryArray) {
  464. if ([cache isEqualToString:string]) {
  465. return;
  466. }
  467. }
  468. [self.dataDistoryArray insertObject:string atIndex:0];
  469. [_TDFileStorage saveHistorySearchBySearchType:self.historySearchType WithArr:self.dataDistoryArray];
  470. [self.collectionView reloadData];
  471. }
  472. /**********************************************************************/
  473. #pragma mark - UISearchBarDelegate
  474. /**********************************************************************/
  475. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  476. }
  477. - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
  478. {
  479. if (searchBar.text.length > 0) {
  480. [self selectIndexText:searchBar.text];
  481. [self checkRepeatString:searchBar.text];
  482. }
  483. }
  484. - (void)textDidChange:(NSString *)text {
  485. if (text.length > 0) {
  486. [self selectIndexText:text];
  487. }
  488. }
  489. //- (void)searchBarTextDidBeginEditing:(UISearchBar *) searchBar{
  490. // UITextField *searchBarTextField = nil;
  491. // NSArray *views = ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) ? searchBar.subviews : [[searchBar.subviews objectAtIndex:0] subviews];
  492. //
  493. // for (UIView *subview in views){
  494. // if ([subview isKindOfClass:[UITextField class]]){
  495. // searchBarTextField = (UITextField *)subview;
  496. // break;
  497. // }
  498. // }
  499. // searchBarTextField.enablesReturnKeyAutomatically = NO;
  500. //}
  501. //- (void)showCancelBtn
  502. //{
  503. // if (self.cancelBtn.hidden) {
  504. // self.cancelBtn.hidden = NO;
  505. // [self.cancelBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  506. // make.right.mas_equalTo(self.navBarV.mas_right).offset(-15);
  507. // make.centerY.mas_equalTo(self.backBtn);
  508. // }];
  509. // }
  510. //}
  511. //- (void)upCanCelBtnConstraits
  512. //{
  513. // self.cancelBtn.hidden = YES;
  514. // [self.cancelBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
  515. // make.right.mas_equalTo(self.navBarV.mas_right);
  516. // make.centerY.mas_equalTo(self.backBtn);
  517. // make.width.mas_offset(0);
  518. // }];
  519. //}
  520. //- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope{
  521. // NSLog(@"%@1",searchBar.text);
  522. //}
  523. @end