0

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];
ErasmoOliveira
  • 1,416
  • 2
  • 20
  • 40
Mohanraj
  • 587
  • 4
  • 21

1 Answers1

0

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.

Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152
  • can you please share me some sample project using UISearchDisplayController – Mohanraj Mar 11 '15 at 07:21
  • Did you look at the documentation? There's a link to Apple's [sample code](https://developer.apple.com/library/ios/samplecode/TableSearch/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007848) there. – Stephen Darlington Mar 11 '15 at 09:56