Skip to content
高仿微信搜索框,自定义SearchController
Branch: master
Clone or download
Latest commit 55de215 Apr 8, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
JKRSearchDemo tableview悬停处理 Apr 4, 2018
.gitignore update bug Apr 6, 2017
README.md Update README.md Apr 8, 2018
preImage.gif update image Apr 6, 2017

README.md

JKRCustomSearchController

preview 

preview 

模仿微信自定义searchController

和UISearchController相同的使用方式,只需要设置searchBar为tableView的tableHeaderView就可以:

[self.tableView setTableHeaderView:self.searchController.searchBar];

控制器懒加载:

- (JKRSearchController *)searchController {
    if (!_searchController) {
        JKRSearchResultViewController *resultSearchController = [[JKRSearchResultViewController alloc] init];
        _searchController = [[JKRSearchController alloc] initWithSearchResultsController:resultSearchController];
        _searchController.searchBar.placeholder = @"搜索";
        _searchController.hidesNavigationBarDuringPresentation = YES;
        _searchController.searchResultsUpdater = self;
        _searchController.searchBar.delegate = self;
        _searchController.delegate = self;
    }
    return _searchController;
}

搜索结果展示:

#pragma mark - JKRSearchControllerhResultsUpdating
- (void)updateSearchResultsForSearchController:(JKRSearchController *)searchController {
    NSString *searchText = searchController.searchBar.text;
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF CONTAINS %@)", searchText];
    JKRSearchResultViewController *resultController = (JKRSearchResultViewController *)searchController.searchResultsController;
    if (!(searchText.length > 0)) resultController.filterDataArray = @[];
    else resultController.filterDataArray = [self.dataArray filteredArrayUsingPredicate:predicate];
}
You can’t perform that action at this time.