// // SYBase_tbVC.m // LNManager // // Created by EchoShacolee on 2017/4/7. // Copyright © 2017年 lee. All rights reserved. // #import "SYBase_tbVC.h" @interface SYBase_tbVC () @end @implementation SYBase_tbVC - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = KBackGroundColor; _dataSource = [[NSMutableArray alloc]init]; _sectionTitles = [[NSMutableArray alloc]init]; _requsetDic = [[NSMutableDictionary alloc]init]; _resultArray = [[NSMutableArray alloc] init]; _hasSearch = NO; [self myInit]; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if (_searchController.active) { _searchController.active = NO; if (_searchController.searchBar && _searchController.searchBar.superview) { [_searchController.searchBar removeFromSuperview]; } } } -(void)myInit{ _tableView = [[UITableView alloc]initWithFrame:self.view.bounds]; _tableView.dataSource = self; _tableView.delegate = self; [self.view addSubview:_tableView]; self.tableView.tableFooterView = [UIView new]; [self.tableView registerClass:[SelectCell class] forCellReuseIdentifier:@"cellId"]; //设置索引条颜色 // self.tableView.sectionIndexBackgroundColor = [UIColor clearColor]; self.tableView.sectionIndexColor = COLOR_THEME; // _searchController = [[UISearchController alloc]initWithSearchResultsController:nil]; _searchController.searchResultsUpdater = self; _searchController.searchBar.placeholder = @"请输入姓名/证件号/电话"; //设置UISearchController的显示属性,以下3个属性默认为YES //搜索时,背景变暗色 _searchController.dimsBackgroundDuringPresentation = NO; //搜索时,背景变模糊 // _searchController.obscuresBackgroundDuringPresentation = NO; //隐藏导航栏 _searchController.hidesNavigationBarDuringPresentation = NO; [_searchController.searchBar sizeToFit]; _searchController.searchBar.frame = CGRectMake(_searchController.searchBar.frame.origin.x, _searchController.searchBar.frame.origin.y, _searchController.searchBar.frame.size.width, 44.0); self.tableView.tableHeaderView = _searchController.searchBar; self.holderV = [[HolderView alloc] initWithFrame:_tableView.frame]; [self.holderV freshBlock:^{ if (_block) { _block(); } }]; [self.view addSubview:self.holderV]; } #pragma mark 获取数据 -(void)getDataWithDic:(NSMutableDictionary *)mdic method:(NSString *)method block:(Block)block{ //判断网络是否连接 if (![NetworkManager connectedToNetWork]) { [self showMsgByAlertVCWithString:@"网络连接异常"]; return; } [MBProgressHUD hideHUDForView:self.view animated:NO]; [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [NetworkManager requestWithMethod:method parameters:mdic type:0 handler:^(NSDictionary *successDic, NSString *failureStr) { [MBProgressHUD hideHUDForView:self.view animated:YES]; [self.holderV setHidden:NO]; if (failureStr) { [self showMsgByAlertVCWithString:failureStr]; return; } if ([successDic[@"code"] isEqualToString:@"1"]) { [self showMsgByAlertVCWithString:successDic[@"msg"]]; return; } if (block) { block(successDic); } }]; } #pragma mark 弹出框提示 - (void)showMsgByAlertVCWithString:(NSString *)str{ UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]]; [self presentViewController:alertFind animated:true completion:nil]; } - (void)showMsgByMBWithString:(NSString *)str{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeText; hud.label.text = str; hud.margin = HUD_MARGIN; hud.removeFromSuperViewOnHide = YES; [hud hideAnimated:YES afterDelay:2]; } #pragma mark 代理方法 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ if (_hasSearch) { return 1; } return _dataSource.count; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (_hasSearch) { return _resultArray.count; } return [_dataSource[section] count]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 44; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"unuse"]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"unuse"]; } return cell; } // 每个分区的页眉 -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if (_hasSearch) { return nil; } return [_sectionTitles objectAtIndex:section]; } // 索引目录 -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { if (_hasSearch) { return nil; } return _sectionTitles; } // 点击目录(响应索引点击) -(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { // 获取所点目录对应的indexPath值 NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:index]; // 让table滚动到对应的indexPath位置 [tableView scrollToRowAtIndexPath:selectIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES]; return index; } - (void)updateSearchResultsForSearchController:(UISearchController *)searchController{ //消除黄色警告 } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end