ResponsiblePersonViewController.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //
  2. // ResponsiblePersonViewController.m
  3. // IBOSS
  4. //
  5. // Created by apple on 2017/5/27.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:责任人控制器
  9. //
  10. #import "ResponsiblePersonViewController.h"
  11. #import "ResponsiblePersonCell.h"
  12. @interface ResponsiblePersonViewController ()<UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate>
  13. /**
  14. 查询bar
  15. */
  16. @property (nonatomic,strong) UISearchBar *searchBar;
  17. /**
  18. 责任人
  19. */
  20. @property (nonatomic,strong) UITableView *tableViewPerson;
  21. @end
  22. @implementation ResponsiblePersonViewController
  23. #pragma mark - 公共事件
  24. /**
  25. viewDidLoad事件
  26. */
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. self.navigationItem.title = @"请选择";
  30. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  31. [button setImage:[UIImage imageNamed:@"icon_back"]
  32. forState:UIControlStateNormal];
  33. [button addTarget:self action:@selector(sGotoBack)
  34. forControlEvents:UIControlEventTouchUpInside];
  35. button.frame = CGRectMake(0, 0,45,22);
  36. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
  37. self.navigationItem.leftBarButtonItem = menuButton;
  38. [self.navigationController setNavigationBarHidden:NO];
  39. self.tableViewPerson = [UITableView new];
  40. self.tableViewPerson.dataSource=self;
  41. self.tableViewPerson.delegate=self;
  42. self.tableViewPerson.frame=CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-rectNavHeight - rectStatusHeight - 1) ;
  43. [self.view addSubview:self.tableViewPerson];
  44. //搜索框
  45. self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
  46. self.searchBar.delegate=self;
  47. self.tableViewPerson.tableHeaderView = self.searchBar;
  48. }
  49. /**
  50. viewWillAppear事件
  51. @param animated <#animated description#>
  52. */
  53. - (void)viewWillAppear:(BOOL)animated{
  54. if(!_arrFilter){
  55. _arrFilter = [[NSMutableArray alloc]init];
  56. }
  57. if(!_arrSearch){
  58. _arrSearch = [[NSMutableArray alloc]init];
  59. }
  60. [self reloadData];
  61. }
  62. /**
  63. dealloc事件
  64. */
  65. - (void)dealloc{
  66. [self cancel];
  67. }
  68. #pragma mark - 回调函数
  69. #pragma mark - tableveiw回调函数
  70. /**
  71. 单元格高度
  72. @param tableView <#tableView description#>
  73. @param indexPath <#indexPath description#>
  74. @return <#return value description#>
  75. */
  76. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  77. UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
  78. return cell.frame.size.height;
  79. }
  80. /**
  81. 单元格
  82. @param tableView <#tableView description#>
  83. @param indexPath <#indexPath description#>
  84. @return <#return value description#>
  85. */
  86. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  87. static NSString *CellIdentifier = @"ResponsiblePersonCell";
  88. ResponsiblePersonCell *cell =(ResponsiblePersonCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  89. if(cell == nil){
  90. NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:CellIdentifier owner:nil options:nil];
  91. cell = [nibs lastObject];
  92. cell.backgroundColor = [UIColor clearColor];
  93. }
  94. ResponsiblePersonModel *info=self.arrFilter[indexPath.row];
  95. cell.lblCode.text = info.staffCode;
  96. cell.lblName.text = info.staffName;
  97. cell.staffid = info.staffID;
  98. return cell;
  99. }
  100. /**
  101. 单元格点击事件
  102. @param tableView <#tableView description#>
  103. @param indexPath <#indexPath description#>
  104. */
  105. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  106. ResponsiblePersonModel *info = self.arrFilter[indexPath.row];
  107. if ([self.respDelegate respondsToSelector:@selector(updateResponsiblePerson:)]) {
  108. [self.respDelegate updateResponsiblePerson:info];
  109. }
  110. [self.navigationController popViewControllerAnimated:YES];
  111. }
  112. /**
  113. 数据源
  114. @param tableView <#tableView description#>
  115. @param section <#section description#>
  116. @return <#return value description#>
  117. */
  118. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  119. return self.arrFilter.count;
  120. }
  121. #pragma mark - 数据回调函数
  122. #pragma mark searchbar回调
  123. /**
  124. 开始编辑
  125. @param searchBar <#searchBar description#>
  126. @return <#return value description#>
  127. */
  128. - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
  129. {
  130. [self addCancelButton];
  131. return YES;
  132. }
  133. /**
  134. 如何实现对UITextField ,UITextView等输入框的 字数限制
  135. @param searchBar <#searchBar description#>
  136. @param range <#range description#>
  137. @param text <#text description#>
  138. @return <#return value description#>
  139. */
  140. - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  141. {
  142. return YES;
  143. }
  144. /**
  145. textDidChange回调
  146. @param searchBar <#searchBar description#>
  147. @param searchText <#searchText description#>
  148. */
  149. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  150. {
  151. if ([searchText isEqualToString:@""]) {
  152. self.arrFilter = _arrSearch;
  153. [self.tableViewPerson reloadData];
  154. return;
  155. }
  156. NSString *keyName = @"name";
  157. //< 模糊查找
  158. NSPredicate *predicateString = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", keyName, searchText];
  159. NSMutableArray *filteredArray = [NSMutableArray arrayWithArray:[_arrSearch filteredArrayUsingPredicate:predicateString]];
  160. self.arrFilter = filteredArray;
  161. [self changeArrToModel:self.arrFilter];
  162. [self.tableViewPerson reloadData];
  163. }
  164. /**
  165. 点击事件
  166. @param searchBar <#searchBar description#>
  167. */
  168. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
  169. {
  170. [searchBar resignFirstResponder];
  171. [self cancelSearch];
  172. }
  173. /**
  174. 开始拖动
  175. @param scrollView <#scrollView description#>
  176. */
  177. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  178. {
  179. [_searchBar resignFirstResponder];
  180. [self cancelSearch];
  181. }
  182. #pragma mark - 私有函数
  183. /**
  184. 进度条隐藏
  185. */
  186. - (void)cancel {
  187. [self stopLoading];
  188. }
  189. /**
  190. 返回事件
  191. */
  192. - (void)sGotoBack
  193. {
  194. [self dismissViewControllerAnimated:YES completion:nil];
  195. [self.navigationController popViewControllerAnimated:YES];
  196. }
  197. /**
  198. 数据加载
  199. */
  200. - (void)reloadData
  201. {
  202. [self.tableViewPerson reloadData ];
  203. }
  204. /**
  205. 取消按钮
  206. */
  207. - (void)addCancelButton
  208. {
  209. //添加取消按钮
  210. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
  211. [button2 addTarget:self action:@selector(cancelSearch)
  212. forControlEvents:UIControlEventTouchUpInside];
  213. button2.frame = CGRectMake(0, 0, 40, 24);
  214. [button2 setTitle:@"取消" forState:UIControlStateNormal];
  215. [button2 setTitleColor:NavBarItemColor forState:UIControlStateNormal];
  216. UIBarButtonItem *menuButton2 = [[UIBarButtonItem alloc] initWithCustomView:button2];
  217. self.navigationItem.rightBarButtonItem = menuButton2;
  218. }
  219. /**
  220. 查询取消
  221. */
  222. - (void)cancelSearch
  223. {
  224. [_searchBar resignFirstResponder];
  225. [self removeCancel];
  226. }
  227. /**
  228. 取消隐藏
  229. */
  230. - (void)removeCancel
  231. {
  232. self.navigationItem.rightBarButtonItem = nil;
  233. }
  234. /**
  235. 数据model
  236. @param arr <#arr description#>
  237. */
  238. - (void)changeArrToModel:(NSArray* )arr{
  239. if(arr != nil){
  240. }
  241. }
  242. @end