Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UITableView Footer doesn't lock in the bottom as the table view is scrolled

I have checked all these UITableView, make footer stay at bottom of screen?

tableFooterView property doesn't fix the footer at the bottom of the table view

iOS - viewForFooterInSection sticking to bottom of UITableView

Proper way to implement a footer in UITableView

similar questions but unfortunately my problem hasn't resolved.

I have to implement a custom header and footer views with buttons inside. I have created separate UIView's subclasses with .nib files. In my view controller, I'm calling these methods to register nibs for header and footer view.

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    CustomTableHeaderView *view = [CustomTableHeaderView header];
    view.delegate = self; //setting delegate to receive callbacks as the buttons inside the view are pressed
    return view;
}

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    CustomTableFooterView *view = [CustomTableFooterView footer];
    view.delegate = self;
    return view;
}

Where as the class method in the custom views registers a .nib file and returns the view. However the implementation is;

+ (CustomTableHeaderView*)header
{
    return [[[NSBundle mainBundle]loadNibNamed:@"CustomTableHeaderView" owner:nil options:nil]objectAtIndex:0];
}

Similar implementation for footer.

The problem is that the footer view doesn't lock at the bottom when the table view scrolls. i-e, when there are more rows to fit inside the view, the footer view hides and is revealed when all the rows are scrolled down till the end. I want to lock the footer view at the bottom of the view no matter how much rows are there to scroll. The header view has been implemented perfectly by this implementation as it is locked at the top while the rows are being scrolled, however the footer view is scrolled with the rows.

I have also tried self.tableview.tablefooterview property but it didn't help either.

like image 869
user3404693 Avatar asked Mar 11 '14 06:03

user3404693


1 Answers

Unfortunately thats not how table section footers work. In order to accomplish an anchored view at the bottom you will need to add it as a subview to your UIView manually.

If you add it as a subview to your UITableView you will need to keep it anchored by changing its frame in scrollViewDidSroll:. If you add it as a subview to the UIView containing your UITableView you can just place it statically at the bottom. In either case you probably want to adjust the contentInset of the table view with an inset at the bottom so that you can scroll your content up above the anchored footer.

like image 112
Dima Avatar answered Oct 15 '22 02:10

Dima