//我们在使用 UITableView的时候, 一般使用默认格式plain,当使用此格式的情况下,上下滑动UITableView页面,我们设置的分区区头,会悬浮在页面的最上方,使用以下代码,可使分区区头跟随UITableView一起滚动.
// UITableView设置分区头跟随UITableView滚动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 50; //根据实际情况设置
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}