views:

373

answers:

2

In my iPhone application I am writing I have a search bar and search display controller. When the user types something in the search box, the table view loads and is now visible. When a user clicks on a row, I would like to get rid of the tableView and go back to the view where the user originally clicked the search bar. I have searched all over the documentation, I cannot find how to do this anywhere. I have 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.

A: 

you can try smth like

[mySerchDisplayController setActive:NO animated:YES];
Morion
I already tried that, it just hides the keyboard, the UITableView is still there.
kylef
i've updated post
Morion
That didn't work either.
kylef
A: 

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];
}
bpapa
Using: [tableView removeFromSuperview]; [searchBar resignFirstResponder]; [searchBar setText:nil];This removes the keyboard and the tableview, but I am left with the Cancel button still there next to the UISearchBar. Thanks for the help so far. Is there no way to remove this cancel button?
kylef