我想知道是否有任何方法实现这样的UI功能。正如我们所知道的,当我们在xcode 5中拖入搜索栏和searchDisplay控件时,我们会得到一组搜索控件,包括一个搜索栏和一个searchDisplayController。
我不想使用本地搜索栏,而是使用一个按钮来触发搜索显示控件,就像在最新的facebook应用程序中那样。
我试着删除搜索栏。但显示控件直接失败。我尝试在tableView中插入搜索栏(我不知道它是否正确)

- (void)viewDidLoad
{
[self hideSearchBar];
}
- (void)hideSearchBar
{
self.UISearchBar.hidden = YES;
self.UISearchBar.bounds = CGRectMake(0, 0, 0, 0);
}
- (IBAction)SearchClicked:(UIButton *)sender {
[self.searchDisplayController setActive:YES animated:NO];
self.UISearchBar.hidden = NO;
}
- (void) searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{
[self hideSearchBar];
}但问题是:
取消搜索时,滚动视图不会返回到以前的状态。(隐藏的searchBar存在一个空白空间)。
而不是看到这一点:

当单击“搜索”视图中的“取消”按钮时,我希望看到这一点。

我如何处理这个问题?
有人能给我一个更好的解决方案吗?
谢谢
发布于 2013-11-11 22:16:24
最后,不要将searchBar控件拖到情节提要中。我正在动态创建和销毁searchBarControl。
-(void)initialiseSearch
{
//Start
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchBar.delegate = self;
searchBar.showsCancelButton = YES;
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
[self.view addSubview:searchBar];
searchBar.hidden = YES;
[searchDisplayController setActive:NO animated:NO];
// [self.searchDisplayController.searchResultsTableView registerNib:[UINib nibWithNibName:@"CustomSearch" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"search"];
//End
}该方法是在视图did加载中调用的。
发布于 2013-10-25 08:13:59
太简单了!
-(void) searchBarCancelButtonClicked:(UISearchBar *)searchBar{
[self.searchDisplayController setActive:NO animated:YES];
self.navigationController popToViewController:UIViewControllerA animated:YES;
}发布于 2013-10-25 04:32:12
根据滚动视图的原始中心创建一个CGPoint。在viewDidLoad()中:
self.originalCenter = scrollView.center;当用户关闭搜索栏时:
- (void)hideSearchBar
scrollView.center = self.originalCenter;scrollView是你称之为UIScrollView的任何东西。
https://stackoverflow.com/questions/19580503
复制相似问题