SearchBar 方法已弃用问题

SearchBar method deprecated issue

提问人:subbu 提问时间:5/5/2017 最后编辑:BSMPsubbu 更新时间:5/6/2017 访问量:387

问:

我使用了这种方法,但它说它已被弃用。我应该使用哪种方法代替此方法?

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

        return YES;
    }
IOS 目标-C IOS7 IOS5

评论

0赞 Larme 5/5/2017
究竟弃用了什么方法?你读过每个人的文档吗?可能会有关于使用什么方法的指示。另外,这些标签是怎么回事?
0赞 NAVEEN KUMAR 5/5/2017
-(BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ return YES; }
1赞 Larme 5/5/2017
阅读以下文档:UISearchDisplayDelegateImportant: UISearchDisplayDelegate is deprecated in iOS 8. (Note that UISearchDisplayController is also deprecated.) To manage the presentation of a search bar and display search results in iOS 8 and later, instead use UISearchControllerDelegate.

答:

0赞 Lalit kumar 5/5/2017 #1

UISearchDisplayController 类替换 UISearchController 类

 - (void)updateSearchResultsForSearchController:(UISearchController *)searchController
 {
    // Your logic here
 }

 - (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
 {
  //[self updateSearchResultsForSearchController:searchController];
 }
0赞 user3182143 5/6/2017 #2

苹果文档说

UISearchDisplayController 在 iOS 8 中已弃用。(请注意, UISearchDisplayDelegate 也已弃用。要管理 在 iOS 8 中显示搜索栏并显示搜索结果,以及 稍后,请改用 UISearchController