简体   繁体   English

将Searchbar添加到NavigationBar,但TableViewCells不加载信息

[英]Adding Searchbar to NavigationBar but TableViewCells not loading information

I used to have a UISearchDisplayController in my TableViewController but I have recently changed it to a UISearchBar and added it to my NavigationBar. 我以前在TableViewController中有一个UISearchDisplayController,但是最近我将其更改为UISearchBar并将其添加到我的NavigationBar中。 I have added a UISearchBar to my Navigation titleView because I want it to be similar to the latest Twitter App. 我已将UISearchBar添加到我的导航titleView中,因为我希望它与最新的Twitter App相似。 The issue that I am currently having is that I do not know how to display the search results in the table view. 我当前遇到的问题是我不知道如何在表格视图中显示搜索结果。 I can see that the searches are being made because I NSLogged searchbar.text. 我可以看到正在搜索,因为我NSLogged searchbar.text。 When I was using UISearchDisplayController it had a SearchResultsTableView but now I don't know how to make it display on the table view. 当我使用UISearchDisplayController时,它具有SearchResultsTableView,但现在我不知道如何使其显示在表格视图中。 Anyone have any guidance or help? 有人有指导或帮助吗? Anything is appreciated. 一切都赞赏。

Note: I have seen tutorials and post about adding search bar to navigation bar or using uisearchdisplaycontroller with a table view. 注意:我看过教程和帖子,内容涉及将搜索栏添加到导航栏或将uisearchdisplaycontroller与表视图一起使用。 I have tried adding the UISearchDisplayController to the navigationbar but it doesn't seem to work either. 我尝试将UISearchDisplayController添加到导航栏中,但似乎也不起作用。 I'm using a UISearchBar and want it to update my table view controller. 我正在使用UISearchBar,并希望它更新我的表视图控制器。 Here is an image to how twitter's search looks: http://i.imgur.com/BiiQHjp.png 这是Twitter搜索外观的图像: http : //i.imgur.com/BiiQHjp.png

You can simply make a UITableView which will display your search results, make your view controller implement UITableViewDelegate and DataSource . 您可以简单地制作一个UITableView来显示您的搜索结果,使您的视图控制器实现UITableViewDelegateDataSource And if you want to make a live search then in searchbar -(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText reload your table view with new data or reload it in - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar if you want static search. 如果要进行实时搜索,请在搜索-(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText用新数据重新加载表格视图,或在- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar如果您要静态搜索)。 I don't think twitter or linkedin apps use searchDisplayController - they just use custom search based on UISearchBar delegates as I described, because UISearchDisplay controller is quite limited when you want full search customiztion. 我不认为twitter或Linkedin应用程序使用searchDisplayController ,它们只是使用基于UISearchBar委托的自定义搜索,如我所述,因为当您要完全搜索自定义时, UISearchDisplay控制器非常有限。 I very rarely use it because of it. 我很少因为它而使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM