UITableView Section Footer overlaps when scrolling
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>=heightFo开发者_如何学编程rHeader) {
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); }
I ran into the same kind of issue today for small screen iphone. May be it will be helpful for someone who deals with tableview with less number of cells in section with big header/Footer views.
First of all, the Headers and footers wont scroll along the cell unless you don't have any more cell to view while scrolling. So, if you got just two or three cells and a big Footer view then it will definitely over lap. One way to tackle this is adding the footer view as last cell of the section. This is just my work around.
精彩评论