1

Я, очевидно, все еще новичок в Xcode. Итак, SeacrhDisplayController устарел в iOS 8, и я не знаю, как реализовать UIsearchController на представлении таблицы.Как заменить SearchDisplayController (Устаревший в IOS 8) методом UIsearchController

У меня есть обход, но я не вижу в нем каких-либо конкретных или ясных учебников.

Вот мой код SearchDisplayController:

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller 
    shouldReloadTableForSearchString:(NSString *)searchString 
    { 
     [self filterContentForSearchText:searchString 
            scope:[[self.searchDisplayController.searchBar scopeButtonTitles] 
              objectAtIndex:[self.searchDisplayController.searchBar 
                 selectedScopeButtonIndex]]]; 

     return YES; 
    } 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if (tableView == self.searchDisplayController.searchResultsTableView) { 
     return [searchResults count]; 

    } else { 
     return [categories count]; 
    } 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"FirstTableCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
    } 
    if (tableView == self.searchDisplayController.searchResultsTableView) { 
     cell.textLabel.text = [searchResults objectAtIndex:indexPath.row]; 
    } else { 
     cell.textLabel.text = [categories objectAtIndex:indexPath.row]; 

    } 

     cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]]; 


    return cell; 
} 



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (tableView == self.searchDisplayController.searchResultsTableView) { 
     [self performSegueWithIdentifier: @"showArrayDetail" sender: self]; 
    } 
} 


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([segue.identifier isEqualToString:@"showArrayDetail"]) { 
     SecondViewController *destViewController = segue.destinationViewController; 

     NSIndexPath *indexPath = nil; 

     if ([self.searchDisplayController isActive]) { 
      indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow]; 
      destViewController.categoryName = [searchResults objectAtIndex:indexPath.row]; 

     } else { 
      indexPath = [self.tableView1 indexPathForSelectedRow]; 
      destViewController.categoryName = [categories objectAtIndex:indexPath.row]; 

     } 
    } 

} 

ответ

0

Вы проверили из образца кода "Таблица поиска с UISearchController (Obj-C и Swift)" на сайте разработчика компании Apple?

+0

Проблема заключается в том, что это решение требует IOS 8 и мое приложение по-прежнему поддерживает IOS 7. Есть ли какое-то решение работает для всех систем, по крайней мере, пока я бросаю IOS 7? –

3

Я знаю, что этот пост старый, но я столкнулся с такой же вопрос, и я нашел следующие учебники, гораздо проще, чем, например от Apple:

  1. http://www.ioscreator.com/tutorials/add-search-table-view-tutorial-ios8-swift
  2. http://useyourloaf.com/blog/2015/02/16/updating-to-the-ios-8-search-controller.html

Выберите, что более подходит для вашей потребности и имеет счастливое кодирование! не

Приветствия,