我的 TableViewController 中曾经有一个 UISearchDisplayController,但最近我将其更改为 UISearchBar 并将其添加到我的 NavigationBar 中。 我已将 UISearchBar 添加到我的导航 titleView 中,因为我希望它与最新的 Twitter 应用程序类似。我目前遇到的问题是我不知道如何在 TableView 中显示搜索结果。我可以看到正在进行搜索,因为我使用 NSLogged searchbar.text。当我使用 UISearchDisplayController 时,它有一个 SearchResultsTableView 但现在我不知道如何使其显示在 TableView 上。有人有任何指导或帮助吗?任何事情都会受到赞赏。
注意:我看过有关将搜索栏添加到导航栏或使用带有 TableView 的 uisearchdisplaycontroller 的教程和帖子。我尝试将 UISearchDisplayController 添加到导航栏,但它似乎也不起作用。我正在使用 UISearchBar 并希望它更新我的 TableView Controller 。这是 Twitter 搜索的图像:http://i.imgur.com/BiiQHjp.png
最佳答案
您可以简单地创建一个 UITableView
这将显示您的搜索结果,使您的 View Controller 实现 UITableViewDelegate
和DataSource
。如果您想进行实时搜索,请在搜索栏中 -(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
使用新数据重新加载 TableView 或在 - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
中重新加载它如果你想要静态搜索。我不认为 Twitter 或 linkedin 应用程序使用 searchDisplayController
- 他们只是使用基于 UISearchBar
的自定义搜索正如我所描述的代表,因为 UISearchDisplay
当您想要完整的搜索自定义时, Controller 非常有限。因此我很少使用它。
关于ios - 将 Searchbar 添加到 NavigationBar 但 TableViewCells 未加载信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20011801/