ios - 将 Searchbar 添加到 NavigationBar 但 TableViewCells 未加载信息

标签 ios objective-c uitableview uisearchbar

我的 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 实现 UITableViewDelegateDataSource 。如果您想进行实时搜索,请在搜索栏中 -(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/

相关文章:

javascript - 使用 Phonegap 下载文件时 iOS 应用程序崩溃

ios - 以编程方式设置 UITableView 行选择返回 nil

ios - UITableView 字母顺序有问题

swift - 如何将 uitableviewcellselectionstyle.none 设置为静态单元格?

ios - Comscore SDK 未在 Swift 项目中进行跟踪

javascript - iOS Safari 内存泄漏导致应用程序无法使用

iphone - XCode (iOS) 中委托(delegate)的自动导入回调

Objective-C (iOS/ cocoa ) : expand first letter into day of week

ios - 以毫秒为单位转换 DateTime iOS

ios - 使用 AVFoundation 时对什么对象实际包含捕获的图像感到困惑