@interface SearchAddressController : UIViewController<UISearchControllerDelegate, UISearchDisplayDelegate, UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *contectTable;
@property (nonatomic, strong) UISearchController *searchController;
- (void)viewDidLoad {
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.scopeButtonTitles = @[];
self.searchController.searchBar.delegate = self;
self.contectTable.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar sizeToFit];
self.definesPresentationContext = YES;
}
#pragma mark - UISearchController delegate
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSString *searchString = searchController.searchBar.text;
if (searchString.length != 0) {
shouldShowSearchResults = true;
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"self CONTAINS[c] %@", searchString];
searchResultArray = [addressArray filteredArrayUsingPredicate:resultPredicate];
[self.contectTable reloadData];
}else{
shouldShowSearchResults = false;
[self.contectTable reloadData];
}
}
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
[self updateSearchResultsForSearchController:self.searchController];
}