6

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.

Community
  • 1
  • 1
user3404693
  • 555
  • 1
  • 8
  • 19
  • 1
    Thoroughly researched all the helping material available and found that using above UITableView's delegate methods is recommended approach to register custom views which lock at the top or bottom in case of header and footer views respectively. But in my case the footer view is not locked, it always scroll as if it is a part of uitableview cells not the footer. – user3404693 Mar 11 '14 at 06:08
  • you have to use tableview heightForHeaderInSection and heightForFooterInSection and than called your custom header and footer view in viewForHeaderInSection and viewForFooterInSection method. –  Mar 11 '14 at 06:27
  • very similar post: http://stackoverflow.com/questions/12885318/anchor-a-uibutton-to-the-bottom-of-a-uitableviewcontrollers-view – Dima Mar 11 '14 at 08:40

1 Answers1

2

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.

Dima
  • 23,484
  • 6
  • 56
  • 83
  • 2
    Thanks for the answer. Scenario is, if there are fewer rows (cumulative height less than table view's height) then the footer must stick beneath the last row (not static at the bottom of the view) but as the number of row increase (greater than uitableview's height) the footer must be anchored at the bottom of the view. If you could elaborate with code, it would be awesome! – user3404693 Mar 11 '14 at 07:30