【发布时间】:2016-05-19 09:54:10
【问题描述】:
我有 UITableview 控制器,它在标题中有搜索栏。当我向上滚动表格视图并反弹时。但是搜索栏隐藏了。当我向下滚动然后显示搜索栏。谁能告诉我如何再次显示搜索栏?
我尝试了以下代码,但运行不顺利:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 40;//Change as per your table header hight
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
//scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
CGPoint newOffset = CGPointMake(0, -[self.tableView contentInset].top);
[self.tableView setContentOffset:newOffset animated:YES];
}
}
这是错误的视图,滚动后:
【问题讨论】:
-
你能展示你的 viewForHeaderInSection 方法吗?
-
这个标题不是节标题..它的tableview的标题。
-
这是
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if(section==0) { return 35.0; } else { return 25.0; } }部分的代码 -
硬编码的 40 是什么?如果你达到 200 会发生什么
-
它的标题高度正在工作,但我正在 viewdidscroll 中更改它,这就是为什么,它不平滑
标签: ios objective-c uitableview uisearchbardisplaycontrol