UISearchController的简单应用
//颜色
#define UIColorFromRGB(value,a) [UIColor colorWithRed:((float)((value & 0xFF0000) >> 16))/255.0 green:((float)((value & 0xFF00) >> 8))/255.0 blue:((float)(value & 0xFF))/255.0 alpha:a]
//获取状态栏的高度 iPhone X - 44pt 其他20pt
#define StatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UISearchControllerDelegate,UISearchResultsUpdating,UISearchBarDelegate>
@property (nonatomic, strong) UITableViewController *searchResultsController;
@property (nonatomic, retain) UISearchController *searchController;
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation ViewController
#pragma mark -- Life Circle
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
- (void)viewDidLoad {
[super viewDidLoad];
//self.automaticallyAdjustsScrollViewInsets = NO;
self.title = @"选择人员";
self.tableView.backgroundColor = [UIColor grayColor];
//调用初始化searchController - 会使tableView底部出现大块空白
self.tableView.tableHeaderView = self.searchController.searchBar;
[self.tableView setSectionIndexBackgroundColor:[UIColor clearColor]];
// know where you want UISearchController to be displayed
//self.definesPresentationContext = YES;
}
-(void)viewDidLayoutSubviews {
if(self.searchController.active) {
_searchResultsController.tableView.frame = CGRectMake(0, StatusBarHeight+self.searchController.searchBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - (20+54))