简体   繁体   中英

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. I have added a UISearchBar to my Navigation titleView because I want it to be similar to the latest 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. When I was using UISearchDisplayController it had a SearchResultsTableView but now I don't know how to make it display on the table view. 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. I have tried adding the UISearchDisplayController to the navigationbar but it doesn't seem to work either. I'm using a UISearchBar and want it to update my table view controller. Here is an image to how twitter's search looks: 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 . 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. 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. I very rarely use it because of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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