PropsUseVC.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. //
  2. // PropsUseVC.m
  3. // IBOSS
  4. //
  5. // Created by 关宏厚 on 2019/9/16.
  6. // Copyright © 2019 elongtian. All rights reserved.
  7. //
  8. #import "PropsUseVC.h"
  9. @interface PropsUseVC ()
  10. @end
  11. @implementation PropsUseVC
  12. - (void)viewDidLoad {
  13. [super viewDidLoad];
  14. //是否是dismissViewController
  15. if (_isPresentViewFlg) {
  16. UIView *vTitle = [[UIView alloc]init];
  17. vTitle.frame = CGRectMake(0, 0, Screen_Width, 44 + rectStatusHeight);
  18. vTitle.backgroundColor = NavigationBarTintColor;
  19. [self.view addSubview:vTitle];
  20. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  21. [button setImage:[UIImage imageNamed:@"icon_back"]
  22. forState:UIControlStateNormal];
  23. [button addTarget:self action:@selector(gotoBack)
  24. forControlEvents:UIControlEventTouchUpInside];
  25. button.frame = CGRectMake(20, rectStatusHeight + 13, 9, 15);
  26. [vTitle addSubview:button];
  27. UILabel *lblTitle = [[UILabel alloc]init];
  28. lblTitle.frame = CGRectMake(9, rectStatusHeight + 13, Screen_Width-2*9 - 20, 15);
  29. lblTitle.textColor = [UIColor whiteColor];
  30. lblTitle.text = @"请选择";
  31. lblTitle.textAlignment = NSTextAlignmentCenter;
  32. [vTitle addSubview:lblTitle];
  33. }else{
  34. self.navigationItem.title = @"请选择";
  35. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  36. [button setImage:[UIImage imageNamed:@"icon_back"]
  37. forState:UIControlStateNormal];
  38. [button addTarget:self action:@selector(gotoBack)
  39. forControlEvents:UIControlEventTouchUpInside];
  40. button.frame = CGRectMake(0, 0,45,22);
  41. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  42. self.navigationItem.leftBarButtonItem = menuButton;
  43. [self.navigationController setNavigationBarHidden:NO];
  44. }
  45. _tableView = [UITableView new];
  46. //是否是dismissViewController
  47. if (_isPresentViewFlg) {
  48. self.tableView.frame = CGRectMake(0, 44 + rectStatusHeight, self.view.bounds.size.width, self.view.bounds.size.height - 44 - rectStatusHeight - 1) ;
  49. }
  50. else{
  51. self.tableView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-rectNavHeight - rectStatusHeight - 1) ;
  52. }
  53. [self.view addSubview:_tableView];
  54. self.arrSearch = [[NSMutableArray alloc] init] ;
  55. self.arrFilter = [[NSMutableArray alloc] init] ;
  56. //搜索框
  57. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
  58. _searchBar.delegate=self;
  59. self.tableView.tableHeaderView=_searchBar;
  60. self.arrSearch = [[NSMutableArray alloc]initWithArray:_propsList];
  61. self.arrFilter = [[NSMutableArray alloc] initWithArray:_arrSearch];
  62. _tableView.delegate=self;
  63. _tableView.dataSource=self;
  64. [_tableView reloadData];
  65. }
  66. /**
  67. viewWillAppear
  68. @param animated <#animated description#>
  69. */
  70. - (void)viewWillAppear:(BOOL)animated
  71. {
  72. }
  73. #pragma mark - tableView回调
  74. /**
  75. Section
  76. @param tableView <#tableView description#>
  77. @return <#return value description#>
  78. */
  79. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  80. {
  81. return 1;
  82. }
  83. /**
  84. 单元格个数
  85. @param tableView <#tableView description#>
  86. @param section <#section description#>
  87. @return <#return value description#>
  88. */
  89. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  90. {
  91. return self.arrFilter.count;
  92. }
  93. /**
  94. 每个单元格
  95. @param tableView <#tableView description#>
  96. @param indexPath <#indexPath description#>
  97. @return <#return value description#>
  98. */
  99. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  100. {
  101. NSString *CellIdentifier = @"Cell";
  102. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier ];
  103. if(cell == nil)
  104. {
  105. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  106. }
  107. NSDictionary *dic = self.arrFilter[indexPath.row];
  108. cell.textLabel.text = [dic objectForKey:@"DictionaryValue"];
  109. cell.textLabel.textAlignment = NSTextAlignmentCenter;
  110. cell.textLabel.font = [UIFont systemFontOfSize:TextFontOfSize];
  111. return cell;
  112. }
  113. /**
  114. 单元格点击事件
  115. @param tableView <#tableView description#>
  116. @param indexPath <#indexPath description#>
  117. */
  118. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  119. NSDictionary *dic=self.arrFilter[indexPath.row];
  120. BaseIDAndNameModel *model = [BaseIDAndNameModel new];
  121. model.name = [dic objectForKey:@"DictionaryValue"];
  122. if ([self.bDelegate respondsToSelector:@selector(baseIDAndNameDoneDatas : BaseIDAndName:)]){
  123. [self.bDelegate baseIDAndNameDoneDatas:model BaseIDAndName:self.showDialogViewTag];
  124. }
  125. //是否是dismissViewController
  126. if (_isPresentViewFlg) {
  127. [self dismissViewControllerAnimated:YES completion:nil];
  128. }else{
  129. [self.navigationController popViewControllerAnimated:YES];
  130. }
  131. }
  132. /**
  133. 开始编辑
  134. @param searchBar <#searchBar description#>
  135. @return <#return value description#>
  136. */
  137. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  138. {
  139. [self addCancelButton];
  140. return YES;
  141. }
  142. /**
  143. 是否可以查询
  144. @param searchBar <#searchBar description#>
  145. @param range <#range description#>
  146. @param text <#text description#>
  147. @return <#return value description#>
  148. */
  149. - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  150. {
  151. return YES;
  152. }
  153. /**
  154. 文本变化
  155. @param searchBar <#searchBar description#>
  156. @param searchText <#searchText description#>
  157. */
  158. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  159. {
  160. if ([searchText isEqualToString:@""]) {
  161. self.arrFilter = _arrSearch;
  162. [_tableView reloadData];
  163. return;
  164. }
  165. NSString *keyName = @"DictionaryValue";
  166. //< 模糊查找
  167. NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K contains[cd] %@", keyName, searchText];
  168. NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearch filteredArrayUsingPredicate:predicateString]];
  169. self.arrFilter = filteredArray;
  170. [_tableView reloadData];
  171. }
  172. /**
  173. 查询点击事件
  174. @param searchBar <#searchBar description#>
  175. */
  176. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  177. {
  178. [searchBar resignFirstResponder];
  179. [self cancelSearch];
  180. }
  181. /**
  182. 开始拖动
  183. @param scrollView <#scrollView description#>
  184. */
  185. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  186. {
  187. [_searchBar resignFirstResponder];
  188. [self cancelSearch];
  189. }
  190. #pragma mark - 私有函数
  191. /**
  192. 进度条隐藏
  193. */
  194. - (void)cancel {
  195. [self stopLoading];
  196. }
  197. /**
  198. 添加取消按钮
  199. */
  200. - (void)addCancelButton
  201. {
  202. //添加取消按钮
  203. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  204. [button addTarget:self action:@selector(cancelSearch)
  205. forControlEvents:UIControlEventTouchUpInside];
  206. button.frame = CGRectMake(0, 0, 40, 24);
  207. [button setTitle:@"取消" forState:UIControlStateNormal];
  208. [button setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  209. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  210. self.navigationItem.rightBarButtonItem = menuButton;
  211. }
  212. /**
  213. 取消查询
  214. */
  215. - (void)cancelSearch
  216. {
  217. [_searchBar resignFirstResponder];
  218. [self removeCancel];
  219. }
  220. /**
  221. 取消按钮隐藏
  222. */
  223. - (void) removeCancel
  224. {
  225. self.navigationItem.rightBarButtonItem = nil;
  226. }
  227. /**
  228. 返回父界面
  229. */
  230. - (void)gotoBack
  231. {
  232. //是否是dismissViewController
  233. if (_isPresentViewFlg) {
  234. [self dismissViewControllerAnimated:YES completion:nil];
  235. }else{
  236. [self.navigationController popViewControllerAnimated:YES];
  237. }
  238. }
  239. @end