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 "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. }else{
  33. [weakSelf.navigationController popViewControllerAnimated:YES];
  34. }
  35. };
  36. _topNavSearch.cancelBlock = ^{
  37. if (weakSelf.cancelBlock) {
  38. weakSelf.cancelBlock();
  39. }
  40. weakSelf.collectionView.hidden = NO;
  41. weakSelf.noDataView.hidden = YES;
  42. weakSelf.tableView.hidden = YES;
  43. };
  44. // self.topNavSearch.backBlock = ^{
  45. // if (weakSelf.cancelBtn.isHidden) {
  46. // [weakSelf.navigationController popViewControllerAnimated:YES];
  47. // }else{
  48. // weakSelf.collectionView.hidden = NO;
  49. // weakSelf.noDataView.hidden = YES;
  50. // weakSelf.tableView.hidden = YES;
  51. // // [weakSelf upCanCelBtnConstraits];
  52. // }
  53. // };
  54. // self.topNavSearch.cancelBlock = ^{
  55. // // weakSelf.searchBar.text = @"";
  56. // weakSelf.collectionView.hidden = NO;
  57. // weakSelf.noDataView.hidden = YES;
  58. // weakSelf.tableView.hidden = YES;
  59. // // [weakSelf upCanCelBtnConstraits];
  60. // };
  61. _topNavSearch.menuBlock = ^{
  62. [weakSelf.view endEditing:YES];
  63. [[UtilsTools getWindow] addSubview:weakSelf.drawerView];
  64. weakSelf.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
  65. if (![weakSelf.tabBarController isKindOfClass:[TabBarController class]]) {
  66. [TabBarController sharedTabBarController].tabBar.hidden = NO;
  67. [weakSelf.tabBarController.navigationController popViewControllerAnimated:NO];
  68. }
  69. if ([weakSelf.navigationController.viewControllers count] > 1) {
  70. [weakSelf.navigationController popToRootViewControllerAnimated:NO];
  71. }
  72. switch (indexPath.section) {
  73. case 0:
  74. {
  75. [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
  76. }
  77. break;
  78. case 1:
  79. {
  80. switch (indexPath.row) {
  81. case 0:
  82. {
  83. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  84. }
  85. break;
  86. case 1:
  87. {
  88. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  89. }
  90. break;
  91. default:
  92. {
  93. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  94. }
  95. break;
  96. }
  97. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  98. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
  99. });
  100. }
  101. break;
  102. default:
  103. {
  104. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  105. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  106. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(4 + indexPath.row)}];
  107. });
  108. }
  109. break;
  110. }
  111. };
  112. weakSelf.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);// - kNavigationHeight
  113. };
  114. }
  115. return _topNavSearch;
  116. }
  117. -(DrawerView *)drawerView{
  118. if(!_drawerView){
  119. _drawerView = [[DrawerView alloc] init];
  120. }
  121. return _drawerView;
  122. }
  123. - (UIView *)noDataView
  124. {
  125. if (!_noDataView) {
  126. _noDataView = [UIView new];
  127. _noDataView.hidden = YES;
  128. _noDataView.backgroundColor = [UIColor whiteColor];
  129. }
  130. return _noDataView;
  131. }
  132. - (UILabel *)noDataL
  133. {
  134. if (!_noDataL) {
  135. _noDataL = [UILabel new];
  136. _noDataL.textColor = UIColorHex(#BBBBBB);
  137. _noDataL.font = [UIFont systemFontOfSize:15];
  138. }
  139. return _noDataL;
  140. }
  141. - (UIButton *)cancelBtn
  142. {
  143. if (!_cancelBtn) {
  144. _cancelBtn = [UIButton new];
  145. [_cancelBtn setAttributedTitle:[[NSMutableAttributedString alloc] initWithString:@"取消" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 15],NSForegroundColorAttributeName: UIColorHex(#3979D3)}] forState:UIControlStateNormal];
  146. }
  147. return _cancelBtn;
  148. }
  149. //- (UIButton *)backBtn
  150. //{
  151. // if (!_backBtn) {
  152. // _backBtn = [UIButton new];
  153. // [_backBtn setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
  154. // }
  155. // return _backBtn;
  156. //}
  157. //- (UIButton *)menuBtn
  158. //{
  159. // if (!_menuBtn) {
  160. // _menuBtn = [UIButton new];
  161. // [_menuBtn setImage:IMG(@"back_black_icon") forState:UIControlStateNormal];
  162. // }
  163. // return _menuBtn;
  164. //}
  165. - (UILabel *)lineL
  166. {
  167. if (!_lineL) {
  168. _lineL = [UILabel new];
  169. _lineL.backgroundColor = LINEBGCOLOR;
  170. }
  171. return _lineL;
  172. }
  173. //- (UIView *)navBarV
  174. //{
  175. // if (!_navBarV) {
  176. // _navBarV = [UIView new];
  177. // _navBarV.backgroundColor = [UIColor whiteColor];
  178. // }
  179. // return _navBarV;
  180. //}
  181. //- (UISearchBar *)searchBar
  182. //{
  183. // if (!_searchBar) {
  184. // _searchBar = [UISearchBar new];
  185. // }
  186. // return _searchBar;
  187. //}
  188. - (UICollectionView *)collectionView
  189. {
  190. if (!_collectionView) {
  191. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  192. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  193. layout.sectionInset = UIEdgeInsetsMake(0, 15, 15, 15);
  194. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  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. NSString * name = [self.dataDistoryArray objectAtIndex:indexPath.row];
  382. UILabel * label = [UILabel new];
  383. label.text = name;
  384. label.font = Kfont(13);
  385. CGFloat W = [label sizeThatFits:CGSizeMake(MAXFLOAT, 25)].width;
  386. return CGSizeMake(name.length > 0 ? (W + 22) : 0, 25);
  387. }
  388. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  389. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  390. [self selectIndexText:[self.dataDistoryArray objectAtIndex:indexPath.row]];
  391. }
  392. //footer的size
  393. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  394. {
  395. return CGSizeMake(0, 0);
  396. }
  397. //header的size
  398. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  399. {
  400. return CGSizeMake(SCREEN_WIDTH, 44);
  401. }
  402. //设置每个item水平间距
  403. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  404. {
  405. return 10.f;
  406. }
  407. //设置每个item垂直间距
  408. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  409. {
  410. return 10.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 setImage:IMG(@"mail_clear_Icon") forState:UIControlStateNormal];
  432. WS(weakSelf);
  433. [closeBtn setAction:^{
  434. [weakSelf.dataDistoryArray removeAllObjects];
  435. [_TDFileStorage saveHistorySearchBySearchType:self.historySearchType WithArr:@[]];
  436. [weakSelf.dataDistoryArray addObject:@""];
  437. [weakSelf.collectionView reloadData];
  438. }];
  439. headerView.backgroundColor = [UIColor whiteColor];
  440. return headerView;
  441. }
  442. return nil;
  443. }
  444. - (void)searchButtonAction:(UISearchBar *)searchBar {
  445. if (searchBar.text.length > 0) {
  446. [self selectIndexText:searchBar.text];
  447. }
  448. }
  449. - (void)selectIndexText:(NSString *)text
  450. {
  451. self.topNavSearch.searchBar.text = text;
  452. self.searchText = text;
  453. self.tableView.hidden = NO;
  454. self.collectionView.hidden = YES;
  455. [self checkRepeatString:text];
  456. [self.view endEditing:YES];
  457. if (self.searchBlock) {
  458. self.searchBlock(text);
  459. }
  460. }
  461. - (void)checkRepeatString:(NSString *)string {
  462. for (NSString *cache in self.dataDistoryArray) {
  463. if ([cache isEqualToString:string]) {
  464. return;
  465. }
  466. }
  467. [self.dataDistoryArray insertObject:string atIndex:0];
  468. [_TDFileStorage saveHistorySearchBySearchType:self.historySearchType WithArr:self.dataDistoryArray];
  469. [self.collectionView reloadData];
  470. }
  471. /**********************************************************************/
  472. #pragma mark - UISearchBarDelegate
  473. /**********************************************************************/
  474. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  475. }
  476. - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
  477. {
  478. if (searchBar.text.length > 0) {
  479. [self selectIndexText:searchBar.text];
  480. [self checkRepeatString:searchBar.text];
  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