Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>=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?

like image 611
Smiley Avatar asked Aug 30 '11 03:08

Smiley


2 Answers

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.

like image 76
Nekto Avatar answered Sep 29 '22 11:09

Nekto


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);
    }

like image 21
Kunal Balani Avatar answered Sep 29 '22 12:09

Kunal Balani