4

In my iPhone application 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.

elitalon
  • 9,191
  • 10
  • 50
  • 86
kylef
  • 1,066
  • 1
  • 8
  • 11

2 Answers2

1

you can try smth like

[mySerchDisplayController setActive:NO animated:YES];
Morion
  • 10,495
  • 1
  • 24
  • 33
1

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
  • 21,409
  • 25
  • 99
  • 147
  • 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 Dec 16 '09 at 22:41