如何隐藏UISearchBar创建的UITableView?

时间:2009-12-16 16:29:02

标签: iphone objective-c uisearchbar uisearchdisplaycontroller uisearchbardelegate

在我的iPhone应用程序中,我有一个搜索栏和搜索显示控制器。当用户在搜索框中键入内容时,表视图会加载并且现在可见。当用户点击一行时,我想摆脱tableView并返回用户最初点击搜索栏的视图。我搜索了整个文档,我找不到如何在任何地方这样做。我尝试了[tableView setHidden:YES];,但当用户再次点击搜索栏时,tableView永远不会返回。

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

请有人指出我正确的方向。

2 个答案:

答案 0 :(得分:1)

你可以尝试像

一样的smth
[mySerchDisplayController setActive:NO animated:YES];

答案 1 :(得分:1)

为什么不从视图层次结构中删除表视图?

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

   // update your model based on the current selection

   [tableView removeFromSuperview];
}