-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
Как это исправить?
Посмотрите на документы для 'UISearchDisplayController'. Он рассказывает вам, что делать сейчас. – rmaddy
Я нашел это: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISearchDisplayController_Class/, но это не очень полезно ... – hantoren
Как это не полезно? Вы потрудились прочитать хотя бы первый абзац этих документов? – rmaddy