Search code examples
iosuisearchbaruisearchdisplaycontrolleruisearchcontrolleruisearchbardisplaycontrol

UISearchController created for iOS 8 not supporting for previous versions


Hi I had created an UISearchController to search a tableview in my app, as I came to know that UISearchDisplay Controller methods are being deprecated for iOS 8, now everything works fine in the 8.1 simulator, when I was trying to run my App in iPad which is of ios version 7.1, I found the search bar missing so please me help how to create a search bar which supports all the iOS versions from 6.0

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
    UISearchBar *searchBar = searchController.searchBar;

    if (searchBar.text.length > 0) {
        NSString *text = searchBar.text;
        NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(NSString *play, NSDictionary *dict) {
        NSRange range = [play rangeOfString:text options:NSCaseInsensitiveSearch];

        return range.location != NSNotFound;
    }];

    NSArray *searchResults = [self.dataARR filteredArrayUsingPredicate:predicate];

Solution

  • There isn't a good answer.

    If you want a single implementation, then the correct, current answer is: use UISearchDisplayController. But, as you say, that's deprecated. It works now but may go away at some point in the future.

    Other options:

    • Keep the current UISearchController implementation for iOS 8 users and create a parallel implementation using UISearchDisplayController for iOS 7 users. The advantage of this is you can remove the deprecated version when you no longer need to support iOS 7.
    • Drop support for iOS 7

    For my personal projects I generally pick option 2 but, obviously, this isn't always an option.