我有一个UITableViewController与UISearchDisplayController安装程序的标准方式(与tableView内的搜索栏)。我想要搜索栏开始隐藏 - 真的隐藏起来,不仅仅是滚动as in this solution。然后,我想在用户按下按钮时显示搜索UI,并在用户选择搜索中找到的其中一个项目后再次隐藏(实际上隐藏它)。隐藏UITableView搜索栏
下面是该几乎工作代码:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.searchDisplayController.searchBar.prompt = @"Add an item";
self.searchDisplayController.searchBar.placeholder = @"Type the item name";
// i do this to trigger the formatting logic below
[self.searchDisplayController setActive:YES animated:NO];
[self.searchDisplayController setActive:NO animated:NO];
// rest of my view will appear
}
- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
NSTimeInterval duration = (self.isViewLoaded && self.view.window)? 0.3 : 0.0;
__block CGFloat searchBarHeight = controller.searchBar.frame.size.height;
[UIView animateWithDuration:duration animations:^{
self.tableView.contentOffset = CGPointMake(0, searchBarHeight);
self.tableView.contentInset = UIEdgeInsetsMake(-searchBarHeight, 0, 0, 0); // trouble here, I think
} completion:^(BOOL finished) {
controller.searchBar.hidden = YES;
}];
}
显示
- (IBAction)pressedAddButton:(id)sender {
self.searchDisplayController.searchBar.hidden = NO;
[self.searchDisplayController setActive:YES animated:YES];
}
我想我正确地设置内容插图,但表现异常,请:如图所示的代码,该表格允许内容向上移动得太远,即只有两个不是很高的行,我可以向下滚动,将这两行中的大部分推到桌面上方......就像没有底部反弹一样。当我注释掉contentInset行时,该表让我将内容拉得太远,在第0行之上留下了很大的差距,大概是搜索栏隐藏起来的地方。
非常感谢,如果任何人都可以提供帮助。
隐藏搜索栏后,表格有2行,每个70px高度,表格高度= 367,内容offset.y = 0,内容inset.top = -75,inset.bottom = 0,全部为预期。什么让我卡在这里是什么导致“底部反弹”?滚动视图不应允许我滚动内容只有140px高,视图367高,但为什么我可以滚动第一行? – danh 2012-03-21 14:53:03