У меня есть приложение, которое выиграет от функции поиска на главном экране. Я написал код, который на полпути выполняет эту задачу, но он не найдет результатов и сработает при нажатии (x) на UISearchBar. Я пытаюсь понять, почему он не работает.Активировать UISearchDisplayController от другого ViewController
Main View Controller (с 'поиск' бар на главном экране):
ViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"];
[self.navigationController pushViewController:viewController animated:YES];
[viewController sendSearchRequest:[nameLabel text] sport:[sportLabel text]];
ViewController (вид с Tableview и UISearchDisplayController)
-(void)sendSearchRequest:(NSString *)request sport:(NSString *)sport{
[self.filteredArray removeAllObjects]; // First clear the filtered array.
self.searchText = request;
/*
* Search the main list for products whose type matches the scope (if
* selected) and whose name matches searchText; add items that match to the
* filtered array.
*/
[self.filteredArray removeAllObjects]; // First clear the filtered array.
self.searchText = request;
/*
* Search the main list for products whose type matches the scope (if
* selected) and whose name matches searchText; add items that match to the
* filtered array.
*/
NSLog(@"Request: %@", request);
for (Athlete *athlete in self.athletes) {
NSComparisonResult result = [[athlete name] compare:request options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [request length])];
if (result == NSOrderedSame) {
[self.filteredArray addObject:athlete];
}
}
[self.searchDisplayController setActive: YES animated: YES];
[self.searchDisplayController.searchBar setText:request];
}