I have a UItableview for which i had the section header & footer programatically.
Initially i had problems with the sectio header overlapping on scroll which i solved using the scrollViewDidScroll delegate as
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
heightForHeader = 40.0;
if (scrollView.contentOffset.y<=heightForHeader&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=heightForHeader) {
scrollView.contentInset = UIEdgeInsetsMake(-heightForHeader, 0, 0, 0);
}
}
now the next issue is with the section footer that is overlapping while scrolling.
Can you help me with this?
Do you set your custom heights for header and footer?
Your table view delegate should implement this methods:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
which should return appropriate values.
If you return smaller values then your header and footer views have, then they may overlap.
You are looking for this: I have tested it and it works
CGFloat sectionFooterHeight = 40; CGFloat tableViewHeight = self.tableView.frame.size.height; if (scrollView.contentOffset.y=tableViewHeight) { scrollView.contentInset = UIEdgeInsetsMake(0, 0,-scrollView.contentOffset.y, 0); } else if (scrollView.contentOffset.y>=sectionFooterHeight+self.tableView.frame.size.height) { scrollView.contentInset = UIEdgeInsetsMake(0, 0,-sectionFooterHeight, 0); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With