UISearchController, uisearchbar
Use of UISearchController in the search box (replacing UISearchBar + UIS after iOS8.0)
1. In iOS 8.0 and later versions, we can use UISearchController to conveniently Add the search box to UITableView. in earlier versions, we still have to use the combination of UISearchBar and UISearchDisplayController.
2. Before using UISearchController, define the following attributes:
// Define a UISearchController @ property (nonatomic, strong) UISearchController * searchController; // It is used to display the search result @ property (nonatomic, strong) ResultViewController * resultVC; // receives the searchController search result @ property (nonatomic, strong) NSMutableArray * searchArr;
// Open up a space to accept the search result _ searchArr = [[NSMutableArray alloc] init]; // instantiate searchController _ searchController = [[UISearchController alloc] initWithSearchResultsController: _ resultVC]; // set the proxy _ searchController called when searching for updates. searchResultsUpdater = self; // set the search box, adaptive, otherwise the search box cannot display [_ searchController. searchBar sizeToFit]; // Add the search box to tableView [_ tableView addSubview: _ searchController. searchBar]; // the following attributes indicate that the settings are not set. // set whether the background is displayed when the search starts. _ searchController. dimsBackgroundDuringPresentation = NO; // when searching, the background is dimmed _ searchController. dimsBackgroundDuringPresentation = NO; // when searching, the background changes to fuzzy _ searchController. obscuresBackgroundDuringPresentation = NO; // hide the navigation bar _ searchController. hidesNavigationBarDuringPresentation = NO;