AllCoachPlanVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. //
  2. // AllCoachPlanVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 16/8/18.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "AllCoachPlanVC.h"
  9. #import "CoachPlanVC.h"
  10. #import "HolderView.h"
  11. #import "AllCoachCell.h"
  12. @interface AllCoachPlanVC ()<UITableViewDelegate,UITableViewDataSource,UISearchDisplayDelegate,UISearchResultsUpdating>
  13. {
  14. HolderView *holderV;
  15. UITableView *mainTableView;
  16. UITextField *textField;
  17. UISearchBar *_searchBar;
  18. UISearchController *_searchController;
  19. BOOL isResult;
  20. NSArray *dataArray;
  21. NSMutableArray *resultArray;
  22. }
  23. @end
  24. @implementation AllCoachPlanVC
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self myInit];
  28. }
  29. -(void)viewWillDisappear:(BOOL)animated
  30. {
  31. [super viewWillDisappear:animated];
  32. [self.view endEditing:YES];
  33. //这个一定要写 要不然会在退出去下一个页面时候 搜索栏有一定时间的存留
  34. if (_searchController.active) {
  35. _searchController.active = NO;
  36. if (_searchController.searchBar && _searchController.searchBar.superview) {
  37. [_searchController.searchBar removeFromSuperview];
  38. }
  39. }
  40. }
  41. -(void)viewDidAppear:(BOOL)animated{
  42. [super viewDidAppear:animated];
  43. self.tabBarController.tabBar.hidden = YES;
  44. }
  45. -(void)myInit{
  46. [self setTitle:@"教练列表"];
  47. [self.view setBackgroundColor:backGroundColor];
  48. if (_isNotification == NO)
  49. {
  50. //正常状态
  51. [self configNavigationBar];
  52. }
  53. else
  54. {
  55. //推送状态 要将根视图变回去
  56. UIBarButtonItem* backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(dismissNavgation)];
  57. [backBtn setTintColor:defGreen];
  58. self.navigationController.navigationBar.translucent = NO;
  59. [self.navigationItem setLeftBarButtonItem:backBtn];
  60. }
  61. isResult = NO;
  62. dataArray = [NSArray array];
  63. resultArray = [NSMutableArray array];
  64. // UIView *searchBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 60)];
  65. // searchBar.backgroundColor = backGroundColor;
  66. // [self.view addSubview:searchBar];
  67. // [searchBar addViewWithRect:CGRectMake(5, 59, kSize.width - 10, 1) Color:lineColor];
  68. //
  69. // textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 10, kSize.width - 140, 40)];
  70. // textField.placeholder = @"请输入教练姓名";
  71. // textField.borderStyle = UITextBorderStyleRoundedRect;
  72. // textField.clearButtonMode = UITextFieldViewModeAlways;
  73. // [searchBar addSubview:textField];
  74. //
  75. // UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  76. // searchBtn.frame = CGRectMake(kSize.width - 100, 12, 80, 36);
  77. // searchBtn.backgroundColor = [UIColor brownColor];
  78. // [searchBtn setTitle:@"查询" TextColor:kTitleColor font:FontTitle fotState:UIControlStateNormal];
  79. // [searchBtn borderColor:lineColor width:1 cornorRadios:18];
  80. // [searchBtn target:self tag:1];
  81. // [searchBar addSubview:searchBtn];
  82. mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain];
  83. // mainTableView.y += 60;
  84. mainTableView.height -= kNavOffSet;
  85. mainTableView.delegate = self;
  86. mainTableView.dataSource = self;
  87. mainTableView.rowHeight = 110;
  88. mainTableView.estimatedSectionHeaderHeight = 0;
  89. mainTableView.estimatedSectionFooterHeight = 0;
  90. [self.view addSubview:mainTableView];
  91. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
  92. {
  93. _searchController =[[UISearchController alloc]initWithSearchResultsController:nil];
  94. [_searchController.searchBar sizeToFit];
  95. _searchController.searchResultsUpdater = self;
  96. //这个是在搜索时候将之前的隐藏 包括表 无法点击 适合弹出新的tableviewcontroller 默认yes
  97. _searchController.dimsBackgroundDuringPresentation = NO;
  98. //这个是搜索时候隐藏导航栏
  99. _searchController.hidesNavigationBarDuringPresentation = NO;
  100. _searchController.searchBar.placeholder=@"请输入教练姓名或者电话";
  101. // _contactTable.sectionIndexColor = [UIColor blueColor];
  102. mainTableView.tableHeaderView=_searchController.searchBar;
  103. //[self searchBarTextDidBeginEditing:_searchController.searchBar];
  104. //不用弹出 因为没有单独的tableviewcontroller
  105. //[self presentViewController:_searchController animated:YES completion:nil];
  106. }
  107. else
  108. {
  109. //实例化一个搜索框
  110. _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
  111. //设置背景色
  112. [_searchBar setBarTintColor:[UIColor grayColor]];
  113. //设置搜索框风格
  114. [_searchBar setSearchBarStyle:UISearchBarStyleProminent];
  115. [_searchBar setPlaceholder:@"请输入教练姓名或者电话"];
  116. //设置显示取消按钮
  117. [_searchBar setShowsCancelButton:YES animated:YES];
  118. //设置类型的标题
  119. //[_searchBar setScopeButtonTitles:@[@"按姓名查找",@"按电话查找"]];
  120. //改变索引的颜色
  121. //_contactTable.sectionIndexColor = [UIColor blueColor];
  122. //改变索引选中的背景颜色
  123. //设置表的表头
  124. [mainTableView setTableHeaderView:_searchBar];
  125. //搜索显示器 Display显示
  126. // UISearchDisplayController * displayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
  127. //
  128. // [displayController setDelegate:self];
  129. // [displayController setSearchResultsDataSource:self];
  130. // [displayController setSearchResultsDelegate:self];
  131. }
  132. holderV = [[HolderView alloc] initWithFrame:mainTableView.frame];
  133. [holderV freshBlock:^{
  134. [self getCoachInfos];
  135. }];
  136. [self.view addSubview:holderV];
  137. [self getCoachInfos];
  138. }
  139. -(void)dismissNavgation
  140. {
  141. //推送过来 返回主页面
  142. [myDelegate gotoLoad];
  143. }
  144. -(void)btnClick:(UIButton *)sender
  145. {
  146. [self.view endEditing:YES];
  147. [resultArray removeAllObjects];
  148. if (textField.text.length < 1) {
  149. isResult = NO;
  150. }else{
  151. isResult = YES;
  152. for (NSDictionary *dic in dataArray) {
  153. if ([dic[@"NAME"] containsString:textField.text] || [dic[@"CARTYPE"] containsString:textField.text] || [dic[@"SEX"] containsString:textField.text]) {
  154. [resultArray addObject:dic];
  155. }
  156. }
  157. }
  158. [mainTableView reloadData];
  159. }
  160. #pragma mark maintableview delegate
  161. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  162. {
  163. if (isResult) {
  164. return resultArray.count;
  165. }
  166. return dataArray.count;
  167. }
  168. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  169. {
  170. AllCoachCell *cell = [tableView dequeueReusableCellWithIdentifier:@"allCoach"];
  171. if (cell == nil)
  172. {
  173. cell = [[AllCoachCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"allCoach"];
  174. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  175. }
  176. NSDictionary *dic;
  177. if (isResult) {
  178. dic = resultArray[indexPath.row];
  179. }else{
  180. dic = dataArray[indexPath.row];
  181. }
  182. cell.dataDic = dic;
  183. cell.superVC = self;
  184. return cell;
  185. }
  186. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  187. {
  188. CoachPlanVC *vc = [[CoachPlanVC alloc] init];
  189. if (isResult) {
  190. vc.coachDic = resultArray[indexPath.row];
  191. }else{
  192. vc.coachDic = dataArray[indexPath.row];
  193. }
  194. [self navPushHideTabbarToVC:vc];
  195. }
  196. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  197. {
  198. //[self.view endEditing:YES];
  199. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
  200. {
  201. if (_searchController.searchBar) {
  202. [_searchController.searchBar endEditing:YES];
  203. }
  204. }else{
  205. if (_searchBar) {
  206. [_searchBar endEditing:YES];
  207. }
  208. }
  209. }
  210. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  211. {
  212. return .1;
  213. }
  214. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  215. {
  216. return .1;
  217. }
  218. #pragma mark UISearchDisplayController 代理方法
  219. ////iOS7搜索的时候 会调用这个方法
  220. //- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
  221. //{
  222. // //NSLog(@"searchString====%@",searchString);
  223. // [resultArray removeAllObjects];
  224. //
  225. // if (searchString.length < 1) {
  226. // isResult = NO;
  227. // }else{
  228. // isResult = YES;
  229. // for (NSDictionary *dic in dataArray) {
  230. //
  231. // NSString *numString = @"1234567890";
  232. // if (searchString.length == 1 && [numString containsString:searchString]) {
  233. //
  234. // if ([dic[@"STAR"] integerValue] > [numString integerValue]) {
  235. //
  236. // [resultArray addObject:dic];
  237. // }
  238. // continue;
  239. // }
  240. //
  241. // if ([dic[@"NAME"] containsString:searchString] || [dic[@"CARTYPE"] containsString:searchString] || [dic[@"SEX"] containsString:searchString] || [dic[@"MOBILE"] containsString:searchString]) {
  242. //
  243. // [resultArray addObject:dic];
  244. // }
  245. // }
  246. // }
  247. //
  248. // [mainTableView reloadData];
  249. //
  250. //
  251. //// for (NSString * info in _tableSourceArray)
  252. //// {
  253. //// if ([info rangeOfString:searchString].location != NSNotFound)
  254. //// {
  255. //// [_resultArray addObject:info];
  256. //// }
  257. //// }
  258. ////
  259. //// [_contactTable reloadData];
  260. //
  261. // return YES;
  262. //}
  263. ////点击不同的选择范围的时候调用
  264. //-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
  265. //
  266. //{
  267. // [self searchDisplayController:controller shouldReloadTableForSearchString:_searchBar.text];
  268. // return YES;
  269. //}
  270. //iOS8搜索调用的方法
  271. - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
  272. {
  273. [resultArray removeAllObjects];
  274. NSString *searchString = _searchController.searchBar.text;
  275. if (searchString.length < 1) {
  276. isResult = NO;
  277. }else{
  278. isResult = YES;
  279. for (NSDictionary *dic in dataArray) {
  280. NSString *numString = @"1234567890";
  281. if (searchString.length == 1 && [numString containsString:searchString]) {
  282. if ([dic[@"STAR"] intValue] >= [searchString intValue]) {
  283. [resultArray addObject:dic];
  284. }
  285. continue;
  286. }
  287. if ([dic[@"NAME"] containsString:searchString] || [dic[@"CARTYPE"] containsString:searchString] || [dic[@"SEX"] containsString:searchString] || [dic[@"MOBILE"] containsString:searchString]) {
  288. [resultArray addObject:dic];
  289. }
  290. }
  291. }
  292. [mainTableView reloadData];
  293. }
  294. #pragma mark 异步获取教练信息
  295. -(void)getCoachInfos
  296. {
  297. if (![Util connectedToNetWork]) {
  298. showMsgUnconnect();
  299. return;
  300. }
  301. NSMutableArray *arr=[NSMutableArray array];
  302. NSString* method = @"getSchPlaceCoachs";
  303. if (_fenceSiteID.length > 0) {
  304. [arr addPro:@"dqbh" Value:_dqbh];
  305. [arr addPro:@"placeId" Value:_fenceSiteID];
  306. }else {
  307. [arr addPro:@"jxbh" Value:_searchJXBH];
  308. method = @"getCoachInfos";
  309. }
  310. [MBProgressHUD showLoadToView:self.view];
  311. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  312. [MBProgressHUD hideHUDForView:self.view];
  313. [holderV setHidden:NO];
  314. if (!root) {
  315. ShowMsgFailed();
  316. return;
  317. }
  318. if ([root[@"code"] isEqualToString:@"1"]) {
  319. ShowMsg(root[@"body"]);
  320. return;
  321. }
  322. if ([root[@"body"] count] < 1) {
  323. return;
  324. }
  325. dataArray = root[@"body"];
  326. [holderV setHidden:YES];
  327. [mainTableView reloadData];
  328. }];
  329. }
  330. - (void)didReceiveMemoryWarning {
  331. [super didReceiveMemoryWarning];
  332. }
  333. @end