iOS:UISearchController的简单应用

本文介绍了如何在iOS应用中使用UISearchController进行搜索功能的实现,提供了一个简单的demo,可在GitHub仓库<https://github.com/ITHanYong/UISearchController.git>中获取,适用于Objective-C开发者,通过Xcode进行集成。
摘要由CSDN通过智能技术生成

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))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值