123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- //
- // AllCoachPlanVC.m
- // jiaPei
- //
- // Created by apple on 16/8/18.
- // Copyright © 2016年 JCZ. All rights reserved.
- //
- #import "AllCoachPlanVC.h"
- #import "CoachPlanVC.h"
- #import "HolderView.h"
- #import "AllCoachCell.h"
- @interface AllCoachPlanVC ()<UITableViewDelegate,UITableViewDataSource,UISearchDisplayDelegate,UISearchResultsUpdating,UISearchControllerDelegate>
- {
- HolderView *holderV;
- UITableView *mainTableView;
- UITextField *textField;
- UISearchBar *_searchBar;
- UISearchController *_searchController;
-
- BOOL isResult;
- NSArray *dataArray;
- NSMutableArray *resultArray;
- }
- @end
- @implementation AllCoachPlanVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self myInit];
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self.view endEditing:YES];
-
- RemoveHUD();
- //这个一定要写 要不然会在退出去下一个页面时候 搜索栏有一定时间的存留
- if (_searchController.active) {
- _searchController.active = NO;
- if (_searchController.searchBar && _searchController.searchBar.superview) {
- [_searchController.searchBar removeFromSuperview];
- }
- }
- }
- -(void)myInit{
-
- [self setTitle:@"教练列表"];
- [self.view setBackgroundColor:KBackGroundColor];
- [self goBackByNavigation];
-
- isResult = NO;
- dataArray = [NSArray array];
- resultArray = [NSMutableArray array];
-
-
- mainTableView = [[UITableView alloc] initWithFrame:kFrame style:UITableViewStylePlain];
- mainTableView.height = kSize.height-kNavOffSet;
- mainTableView.delegate = self;
- mainTableView.dataSource = self;
- mainTableView.rowHeight = 110;
- mainTableView.tableFooterView = [UIView new];
- [self.view addSubview:mainTableView];
-
- #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
- //实例化一个搜索框
- _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kSize.width, 40)];
- //设置背景色
- [_searchBar setBarTintColor:[UIColor grayColor]];
- //设置搜索框风格
- [_searchBar setSearchBarStyle:UISearchBarStyleProminent];
-
- [_searchBar setPlaceholder:@"请输入教练姓名或者电话"];
- //设置显示取消按钮
- [_searchBar setShowsCancelButton:YES animated:YES];
- //设置类型的标题
- //[_searchBar setScopeButtonTitles:@[@"按姓名查找",@"按电话查找"]];
- //改变索引的颜色
- //_contactTable.sectionIndexColor = [UIColor blueColor];
- //改变索引选中的背景颜色
-
- //设置表的表头
- [mainTableView setTableHeaderView:_searchBar];
-
- //搜索显示器 Display显示
- UISearchDisplayController * displayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
-
- [displayController setDelegate:self];
- [displayController setSearchResultsDataSource:self];
- [displayController setSearchResultsDelegate:self];
- #else
- _searchController =[[UISearchController alloc]initWithSearchResultsController:nil];
- _searchController.delegate = self;
- [_searchController.searchBar sizeToFit];
- _searchController.searchResultsUpdater = self;
- //这个是在搜索时候将之前的隐藏 包括表 无法点击 适合弹出新的tableviewcontroller 默认yes
- _searchController.dimsBackgroundDuringPresentation = NO;
- //这个是搜索时候隐藏导航栏
- _searchController.hidesNavigationBarDuringPresentation = NO;
- _searchController.searchBar.placeholder=@"请输入教练姓名或者电话";
- // _contactTable.sectionIndexColor = [UIColor blueColor];
- mainTableView.tableHeaderView=_searchController.searchBar;
-
- //[self searchBarTextDidBeginEditing:_searchController.searchBar];
- //不用弹出 因为没有单独的tableviewcontroller
- //[self presentViewController:_searchController animated:YES completion:nil];
- #endif
-
-
-
- holderV = [[HolderView alloc] initWithFrame:mainTableView.frame];
- [holderV freshBlock:^{
-
- [self getCoachInfos];
- }];
- [self.view addSubview:holderV];
-
- [self getCoachInfos];
- }
- -(void)btnClick:(UIButton *)sender
- {
- [self.view endEditing:YES];
-
- [resultArray removeAllObjects];
-
- if (textField.text.length < 1) {
- isResult = NO;
- }else{
- isResult = YES;
- for (NSDictionary *dic in dataArray) {
-
- if ([dic[@"NAME"] containsString:textField.text] || [dic[@"CARTYPE"] containsString:textField.text] || [dic[@"SEX"] containsString:textField.text]) {
-
- [resultArray addObject:dic];
- }
- }
- }
-
- [mainTableView reloadData];
- }
- #pragma mark maintableview delegate
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- if (isResult) {
- return resultArray.count;
- }
- return dataArray.count;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- AllCoachCell *cell = [tableView dequeueReusableCellWithIdentifier:@"allCoach"];
- if (cell == nil)
- {
- cell = [[AllCoachCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"allCoach"];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- }
-
- NSDictionary *dic;
- if (isResult) {
- dic = resultArray[indexPath.row];
- }else{
- dic = dataArray[indexPath.row];
- }
- cell.dataDic = dic;
- cell.superVC = self;
-
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- CoachPlanVC *vc = [[CoachPlanVC alloc] init];
- if (isResult) {
- vc.coachDic = resultArray[indexPath.row];
- }else{
- vc.coachDic = dataArray[indexPath.row];
- }
-
- [self navPushHideTabbarToVC:vc];
- }
- -(void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- //[self.view endEditing:YES];
- if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
- {
- if (_searchController.searchBar) {
- [_searchController.searchBar endEditing:YES];
- }
- }else{
- if (_searchBar) {
- [_searchBar endEditing:YES];
- }
- }
- }
- #pragma mark SearchController Delegate
- -(void)willPresentSearchController:(UISearchController *)searchController{
-
- _searchController.searchBar.showsCancelButton = YES;
- UIButton *canceLBtn = [_searchController.searchBar valueForKey:@"cancelButton"];
- [canceLBtn setTitle:@"取消" forState:UIControlStateNormal];
- [canceLBtn setTitleColor:RQMianColor forState:UIControlStateNormal];
- }
- #pragma mark UISearchDisplayController 代理方法
- //iOS7搜索的时候 会调用这个方法
- #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
- - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
- {
- //NSLog(@"searchString====%@",searchString);
- [resultArray removeAllObjects];
-
- if (searchString.length < 1) {
- isResult = NO;
- }else{
- isResult = YES;
- for (NSDictionary *dic in dataArray) {
-
- NSString *numString = @"1234567890";
- if (searchString.length == 1 && [numString containsString:searchString]) {
-
- if ([dic[@"STAR"] integerValue] > [numString integerValue]) {
-
- [resultArray addObject:dic];
- }
- continue;
- }
-
- if ([dic[@"NAME"] containsString:searchString] || [dic[@"CARTYPE"] containsString:searchString] || [dic[@"SEX"] containsString:searchString] || [dic[@"MOBILE"] containsString:searchString]) {
-
- [resultArray addObject:dic];
- }
- }
- }
-
- [mainTableView reloadData];
-
- return YES;
- }
- //点击不同的选择范围的时候调用
- - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
- {
- [self searchDisplayController:controller shouldReloadTableForSearchString:_searchBar.text];
- return YES;
- }
- #endif
- //iOS8搜索调用的方法
- - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
- {
- [resultArray removeAllObjects];
-
- NSString *searchString = _searchController.searchBar.text;
- if (searchString.length < 1) {
- isResult = NO;
- }else{
- isResult = YES;
- for (NSDictionary *dic in dataArray) {
-
- NSString *numString = @"1234567890";
- if (searchString.length == 1 && [numString containsString:searchString]) {
-
- if ([dic[@"STAR"] intValue] >= [searchString intValue]) {
- [resultArray addObject:dic];
- }
- continue;
- }
-
- if ([dic[@"NAME"] containsString:searchString] || [dic[@"CARTYPE"] containsString:searchString] || [dic[@"SEX"] containsString:searchString] || [dic[@"MOBILE"] containsString:searchString]) {
-
- [resultArray addObject:dic];
- }
- }
- }
-
- [mainTableView reloadData];
- }
- #pragma mark 异步获取教练信息
- -(void)getCoachInfos{
-
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
-
- NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
-
- NSString *method = @"getSchPlaceCoachs";
- if (_fenceSiteID.length > 0) {
- [dic setValue:_fenceSiteID forKey:@"placeId"];
- }else {
- [dic setValue:defUser.userDict[@"school"] forKey:@"schid"];
- method = @"getCoachInfos";
- }
- [NetManager requestAnythingWithURL:method dictionary:dic dataArray:nil completion:^(NSDictionary *root){
-
- [holderV setHidden:NO];
- if (!root) {
- ShowMsg(@"获取教练列表失败!");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowMsg(root[@"msg"]);
- return;
- }
-
- if ([root[@"body"] count] < 1) {
- return;
- }
-
- dataArray = root[@"body"];
-
- [holderV setHidden:YES];
- [mainTableView reloadData];
- }];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- @end
|