如何隐藏 UISearchBar 创建的 UITableView?

发布于 2024-08-15 06:00:11 字数 414 浏览 4 评论 0原文

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

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天的雪花 2024-08-22 06:00:11

你可以尝试像

[mySerchDisplayController setActive:NO 动画:YES];

you can try smth like

[mySerchDisplayController setActive:NO animated:YES];
同展鸳鸯锦 2024-08-22 06:00:11

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

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

   // update your model based on the current selection

   [tableView removeFromSuperview];
}

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文