Smiley
Smiley

Reputation: 51

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?

Upvotes: 5

Views: 4082

Answers (3)

Itzdsp
Itzdsp

Reputation: 912

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.

Upvotes: 0

Kunal Balani
Kunal Balani

Reputation: 4789

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

Upvotes: 1

Nekto
Nekto

Reputation: 17877

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.

Upvotes: 5

Related Questions