【问题标题】:SearchBar method deprecated issueSearchBar 方法已弃用问题
【发布时间】:2017-10-03 19:12:59
【问题描述】:

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

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

        return YES;
    }

【问题讨论】:

  • 究竟什么方法被弃用了?您是否阅读了每个文档的文档?可能有关于使用什么方法的指示。另外,这些标签是什么?
  • -(BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ return YES; }
  • 阅读UISearchDisplayDelegate的文档:Important: 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.

标签: ios objective-c ios7 io ios5


【解决方案1】:

UISearchDisplayController 类替换 UISearchController 类

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

 - (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
 {
  //[self updateSearchResultsForSearchController:searchController];
 }

【讨论】:

    【解决方案2】:

    Apple Document Says

    UISearchDisplayController 在 iOS 8 中已弃用。(请注意 UISearchDisplayDelegate 也已被弃用。)管理 在 iOS 8 中呈现搜索栏并显示搜索结果 稍后,改为使用 UISearchController

    【讨论】:

      猜你喜欢
      • 2020-08-01
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 2022-08-03
      • 2016-06-08
      • 2012-09-20
      • 2020-11-28
      相关资源
      最近更新 更多