【问题标题】:Insert a UISearchBar in IOS 8, Xcode 6 [closed]在 IOS 8、Xcode 6 中插入 UISearchBar [关闭]
【发布时间】:2014-12-24 05:45:01
【问题描述】:

实现UISearchBar 的最佳最有效方式是什么?

我查遍了整个互联网,所有的教程都是针对ios 7版本的,很多方法在ios 8中被弃用了。有人可以提供一个库或如何在 xcode 中为ios 8 实现searchBar 的示例吗?

【问题讨论】:

  • 不清楚你在问什么。请提出具体问题,包括适用的错误消息 - 请参阅 stackoverflow.com/help/how-to-ask
  • 我的问题是,当我实现 UISearchBar 时,我应该如何处理已弃用的代码?我在不推荐使用的部分写了 deprecated 。前任。 self.searchDisplayController.searchResultsTableView
  • 您是否查看过文档以了解已弃用的方法和属性。文档通常会提供推荐的替代方案
  • 很清楚 - 使用 UISearchController 而不是 UISearchDisplayController。如果您想支持 ios8 之前的版本,那么您需要忍受弃用警告

标签: objective-c ios8 xcode6 uisearchbar


【解决方案1】:


几个月前我不得不做和你一样的事情。所以,我在 GitHub 上找到了这个:https://github.com/dempseyatgithub/Sample-UISearchController
下载/克隆它,您将能够看到如何将 UISearchController 与 UITableView 和 UICollectionView 一起使用。它拥有从 UISearchDisplayController 升级到 UISearchController 所需的一切。 UISearchController 文档也很有帮助。
如果您还需要支持 iOS 7(如果您真的打算将应用部署到 App Store,我个人建议您这样做):

if([UISearchController class]){
//Create an UISearchController and add it to your UITableViewController
}else{
//Create an UISearchDisplayController and add it to your UITableViewController 
}

注意:如果您想同时支持这两个版本的 iOS,您必须以编程方式完成所有操作。

最好的问候,
加百列富冢

【讨论】:

  • 实际上我之前确实遇到过,我只是不确定从哪个文件中读取。它有很多不同的文件。
  • 使用 MasterViewController_TableResults 和 MasterViewController_FilterResults 文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多