2015-11-02 2 views
-3

Я хочу добавить панель поиска к существующему классу UIViewController. Я использую iOS 8+ и всегда отлаживаю приложение. У меня будет сообщение об ошибке.Добавить панель поиска в класс UIViewController

я сделал:

.h

@interface mainViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchDisplayDelegate> 

.m

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    if (tableView == self.searchDisplayController.searchResultsTableView) { 
     return [searchResultArray count]; 
    } 
    else{ 
     return [self.fullArray count]; 
    } 
} 

-(void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope{ 
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", searchResultArray]; 
    searchResultArray = [self.fullArray filteredArrayUsingPredicate:predicate]; 

} 

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{ 

    [self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles]objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; 

    return YES; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 
    } 

    if (tableView == self.searchDisplayController.searchResultsTableView) { 
     cell.textLabel.text = [searchResultArray objectAtIndex:indexPath.row]; 
    } 
    else{ 
     cell.textLabel.text = [self.fullArray objectAtIndex:indexPath.row]; 
    } 
} 

Но код даст мне предупреждение:

searchDisplayController is deprecated: first deprecated in iOS 8.0 

Как это исправить?

+0

Посмотрите на документы для 'UISearchDisplayController'. Он рассказывает вам, что делать сейчас. – rmaddy

+0

Я нашел это: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISearchDisplayController_Class/, но это не очень полезно ... – hantoren

+1

Как это не полезно? Вы потрудились прочитать хотя бы первый абзац этих документов? – rmaddy

ответ

1

UISearchDisplayController устарел, и вместо этого рекомендуется использовать UISearchController.

Обратите внимание на то, как использовать UISearchController в вашем приложении.

Смежные вопросы