STTableSearchCell.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // STTableSearchCell.m
  3. // BuguLive
  4. //
  5. // Created by 岳克奎 on 17/5/3.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "STTableSearchCell.h"
  9. @implementation STTableSearchCell
  10. - (void)awakeFromNib {
  11. [super awakeFromNib];
  12. // Initialization code
  13. self.secrchBar.tintColor = kAppMainColor;
  14. self.secrchBar.delegate = self;
  15. }
  16. //当搜索框开始编辑时候调用
  17. -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
  18. //影藏 searchBar
  19. [searchBar setShowsCancelButton:YES
  20. animated:YES];
  21. //tableView 设置
  22. self.tableView.allowsSelection=NO;
  23. self.tableView.scrollEnabled=NO;
  24. }
  25. //当搜索框将要将要结束使用时调用
  26. -(BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar{
  27. //tableView 设置
  28. self.tableView.allowsSelection= YES;
  29. self.tableView.scrollEnabled= YES;
  30. return YES;
  31. }
  32. //当搜索框结束编辑时候调用
  33. -(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
  34. }
  35. //当field里面内容改变时候就开始掉用
  36. -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
  37. }
  38. //在field里面输入时掉用,询问是否允许输入,yes表示允许,默认为yes,否则无法输入
  39. -(BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
  40. NSLog(@"shouldChange");
  41. return YES;
  42. }
  43. //点击CancelButton调用
  44. -(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
  45. //清空
  46. searchBar.text = @"";
  47. //显示取消 按钮
  48. [searchBar setShowsCancelButton:NO
  49. animated:YES];
  50. // 退出编辑
  51. [searchBar resignFirstResponder];
  52. //tableView 设置
  53. self.tableView.allowsSelection=YES;
  54. self.tableView.scrollEnabled=YES;
  55. }
  56. //关键字搜索
  57. -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  58. //显示取消 按钮
  59. [searchBar setShowsCancelButton:NO
  60. animated:YES];
  61. // 退出编辑
  62. [searchBar resignFirstResponder];
  63. //tableView 设置
  64. self.tableView.allowsSelection= YES;
  65. self.tableView.scrollEnabled= YES;
  66. if (_delegate &&[_delegate respondsToSelector:@selector(showSTTableSearchCell:)]) {
  67. [_delegate showSTTableSearchCell:self];
  68. }
  69. }
  70. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  71. [super setSelected:selected animated:animated];
  72. // Configure the view for the selected state
  73. }
  74. @end