您的位置:首页 > 产品设计 > UI/UE

关于UISearchController的使用方法

2016-03-07 17:27 471 查看
首先头文件要引用UISearchBarDelegate

设置属性@property (nonatomic,strong)UISearchController * searchController;

在viewload里面设置:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];//初始化

    

    [self.searchController.searchBar sizeToFit];//自动适应大小

    

    self.tableView.tableHeaderView = self.searchController.searchBar;//tableview的头视图就是searchBar

    

    self.searchController.dimsBackgroundDuringPresentation = YES;

    

    self.searchController.hidesNavigationBarDuringPresentation = NO;

    

    self.searchController.searchBar.delegate = self;

方法:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{

//点击搜索后调用的方法

代码不全,一般这里要调用接口,用srVC的数组接收数据,再转过去到srVC

SearchResultViewController * srVC = [[SearchResultViewController alloc] init];

srVC.searchText = searchBar.text;

[self.navigationController pushViewController:srVC animated:YES];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UISearchController