Search code examples
iphoneuitableviewfooter

When and where should I add a view to a UITableView's footer?


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.


Solution

  • 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.