views:

428

answers:

3

I am populating a UITableViewController's UITableView through code only. At the bottom of the table I wish to position a button that scrolls into view as the user scrolls to the bottom of the table.

When in the UITableViewController life cycle should I populate the table footer with a button? viewDidLoad?

p.s. I wish to avoid using section footers in the UITableView.

A: 

You can just set the tableFooterView property of a UITableView to your button.

zonble
A: 

Yes, put it in viewDidLoad. Here is some sample code.

Frank Schmitt
+1  A: 

Yes, viewDidLoad is the correct place. It's not a stone-set rule though - I have change footer view in many different situations, such as after rotation in didRotateFromInterfaceOrientation.

Note that the view will be repositioned to location immediately below the last row, so if you want to provide a margin or centering for your button I suggest adding a plan UIVIew as footer, and then add your button(s) into that UIView.

DenNukem
Thank you for that confirmation. Is the height of the UITableView known at UITableViewController viewDidLoad? I ask because in one case I need to position the button at the bottom of the screen when the table takes up less than the whole vertical space of the screen.
camelCase
DenNukem