jjxtra jjxtra - 7 months ago 83
iOS Question

How can I get a UITableView tableFooterView to expand to fill the whole parent view?

I have a UIView that I am setting as the property of a UITableView tableFooterView property. In cases where the table view and the footer do not fill the whole parent view, is there a way to determine how much taller I need to make the footer so that it does fill in the remaining space?

My ultimate goal here is to get a delete button to be aligned to the bottom of the view. If the table view is larger than the parent view, I am not going to do anything and the delete button will be off the view to start which is fine.

EDIT This needs to work on iPad in the form sheet modal type, where the view bounds should only be that of the form sheet, not the whole screen.


Off the top of my head: since UITableViews are essentially UIScrollViews, try using the contentSize.height value of your table view to see how much it occupies the screen. Then, adjust the tableFooterView frame to fill the difference in height from its superview's frame height. Essentially:

CGRect tvFrame = tableView.frame;
CGFloat height = tvFrame.size.height - tableView.contentSize.height;
if (height > MIN_HEIGHT) { // MIN_HEIGHT is your minimum tableViewFooter height
    CGRect frame = tableFooterView.frame;
    tableFooterView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, height);