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와 스위프트)와 함께 테이블 검색"샘플 코드를 체크 아웃 적이 있습니까?

+0

문제는이 솔루션이 아이폰 OS (8)을 필요로하고 내 응용 프로그램은 여전히 ​​아이폰 OS 7. 모든 시스템 작업 일부 솔루션이 지원하는 것입니다, 적어도 내가 아이폰 OS 7 드롭까지? –

관련 문제