I have a UITableViewController that show data in cells. In viewWillAppear I add a UIView to tableHeaderView with this method self.tableView.tableHeaderView =headerView;
In headerView I add a UISearchBar and a UISegmentControl programmatically. I set UISearchBar delegate like this
self.searchDisplay.delegate = self;
self.searchDisplay.searchBar.delegate = self;
self.searchDisplay.searchResultsDataSource = self;
self.searchDisplay.searchResultsTableView.delegate = self;
the searchDisplay is UISearchDisplayController.
The search is work perfectly but my problem is when I select one cell from searchResultsTableView and go to another viewController when touch back button in UINavigationController and come back to this view the table doesn’t scroll anymore.
I add this two method in viewDidLoad and viewWillAppear but still doesn’t work
self.tableView.bounces = YES;
self.tableView.scrollEnabled = YES;
It’s work perfectly when I select one row from table without search and go and come back.
What’s the problem ?
You are actually using two tableviews on the view, (
self.tableViewandself.searchDisplay.searchBarTableView) one for showing data, and one for showing the searched data. I think the searchViewController is staying on the screen after the segue.There’s a trick to show the whole data and search results in a single tableView (no need to use
UISearchDisplayController)Just do the following to show the search results:
for the actual data, you can empty the
UISearchBarand load the whole data in table view datasource.