-1

I made a list in tableviewcontroller, then add search bar and search display. But due to the fact that I have an array in Russian language search is not working. If I add the numbers in the array and start search it's work. But if on the Russian letters, no. How to fix it?

My code

    - (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        _items
        =  [NSArray arrayWithObjects:
             @"А",
             @"Ак",
             @"Ба",
             @"Бо",
             @"22", 
             @"23", 
             nil];
    }
    return self;
}

#pragma mark - UISearchDisplayDelegate

// register a cell reuse identifier for the search results table view
-(void)searchDisplayController:(UISearchDisplayController *)controller
 didLoadSearchResultsTableView:(UITableView *)tableView {
    [tableView registerClass:[UITableViewCell class]
      forCellReuseIdentifier:@"SearchResultsTableViewUITableViewCell"];
}

// perform the search
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString {
    NSPredicate *predicate
    = [NSPredicate predicateWithFormat:@"self beginswith %@", searchString];
    NSArray *searchResults
    = [[self items] filteredArrayUsingPredicate:predicate];
    [self setSearchResults:searchResults];

    return YES;
}

#pragma mark - UITableViewDataSource

// check if displaying search results
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
    if ([[self searchDisplayController] isActive]) {
        return [[self searchResults] count];
    } else {
        return [[self items] count];
    }
}

// check if displaying search results
-(UITableViewCell *)tableView:(UITableView *)tableView
        cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([[self searchDisplayController] isActive]) {
        UITableViewCell *cell
        = [tableView dequeueReusableCellWithIdentifier:@"SearchResultsTableViewUITableViewCell"
                                          forIndexPath:indexPath];
        id item = [[self searchResults] objectAtIndex:[indexPath row]];
        [[cell textLabel] setText:item];
        return cell;
    } else {
        UITableViewCell *cell
        = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"
                                          forIndexPath:indexPath];
        id item = [[self items] objectAtIndex:[indexPath row]];
        [[cell textLabel] setText:item];
        return cell;
    }
}

#pragma mark - UITableViewDelegate

// manually perform detail segue after selecting a search result
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([[self searchDisplayController] isActive]) {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        [self performSegueWithIdentifier:@"detailSegue" sender:cell];
    }
}

#pragma mark - UIViewController

/* prepare for detail scene segue
 called after cell selection in the master and
 search results table views */
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UITableViewCell *cell = (UITableViewCell *)sender;

    id item = nil;
    if ([[self searchDisplayController] isActive]) {
        NSIndexPath *indexPath
        = [[[self searchDisplayController] searchResultsTableView] indexPathForCell:cell];
        item = [[self searchResults] objectAtIndex:[indexPath row]];
    } else {
        NSIndexPath *indexPath
        = [[self tableView] indexPathForCell:cell];
        item = [[self items] objectAtIndex:[indexPath row]];
    }

    UIViewController *detail
    = (UIViewController *)[segue destinationViewController];
    [[detail navigationItem] setTitle:item];
}
@end
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59

1 Answers1

0
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [cd] %@", self.searchBar.text];
        self.searchResults = [[_actualItems filteredArrayUsingPredicate:predicate] mutableCopy];
OMGHaveFun
  • 838
  • 1
  • 10
  • 16