How can I hide the UITableView created by the UISearchBar?

In my iPhone application, I have a search bar and a display controller. When the user enters something into the search field, the table view is loaded and is now visible. When the user clicks on a row, I would like to get rid of the tableView and return to the view in which the user initially clicked the search bar. I searched all the documentation, I cannot find how to do this. I tried [tableView setHidden:YES]; but when the user clicks on the search bar again, the tableView never returns.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; } 

Please can someone point me in the right direction.

+4
source share
2 answers

you can try something like

 [mySerchDisplayController setActive:NO animated:YES]; 
+1
source

Why don't you just remove the table view from the view hierarchy?

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; // update your model based on the current selection [tableView removeFromSuperview]; } 
+1
source

All Articles