Iphone 如何隐藏UISearchBar创建的UITableView?
在我的iPhone应用程序中,我有一个搜索栏和搜索显示控制器。当用户在搜索框中键入内容时,表视图将加载并显示。当用户单击一行时,我希望摆脱tableView并返回到用户最初单击搜索栏的视图。我已经搜索了所有的文档,我在任何地方都找不到如何做到这一点。我尝试了Iphone 如何隐藏UISearchBar创建的UITableView?,iphone,objective-c,uisearchbar,uisearchdisplaycontroller,uisearchbardelegate,Iphone,Objective C,Uisearchbar,Uisearchdisplaycontroller,Uisearchbardelegate,在我的iPhone应用程序中,我有一个搜索栏和搜索显示控制器。当用户在搜索框中键入内容时,表视图将加载并显示。当用户单击一行时,我希望摆脱tableView并返回到用户最初单击搜索栏的视图。我已经搜索了所有的文档,我在任何地方都找不到如何做到这一点。我尝试了[tableView setHidden:YES]但当用户再次单击搜索栏时,tableView将永远不会返回 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath
[tableView setHidden:YES]代码>但当用户再次单击搜索栏时,tableView将永远不会返回
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
请有人给我指一下正确的方向。你可以试试看
为什么不从视图层次结构中删除表视图呢
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// update your model based on the current selection
[tableView removeFromSuperview];
}
我已经试过了,它只是隐藏了键盘,UITableView仍然存在;[搜索栏辞职FirstResponder];[搜索栏设置文本:无];这将删除键盘和tableview,但我仍然保留UISearchBar旁边的Cancel按钮。谢谢你迄今为止的帮助。无法删除此取消按钮吗?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// update your model based on the current selection
[tableView removeFromSuperview];
}