我有一個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