I just implemented a Load More button into the footer of my tableView, but the footer is always scrolling with the table. The style of my tableView is UITableViewStylePlain.
Here if you use the table view in-built delegate method,
tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
,
it will appear as fixed at the bottom of the view and it doesn't care about the height of the table view. Even though if you set tableView.tableFooterView?.isUserInteractionEnabled = true
it won't work as you want. So as the solution for this, you have to set the table footer view on viewDidLoad()
(as you are setting delegate and datasource in this method).
let cell = tableView.dequeueReusableCell(withIdentifier: "MyFinanceTableViewFooterCell") as! MyFinanceTableViewFooterCell
tableView.tableFooterView = cell
And this will work as you wish.
First of all, tableView:viewForFooterInSection
does not define a footer for the table, it defines a footer for the section in the table. You can have multiple section footers in one table. In the case where your table is only one section, using this method will be functionally equivalent to adding a table footer, but it is NOT meant to be the table's footer. It is much better practice to use the actual table footer if that's what you want, which can be accomplished by simply assigning a view to the UITableView
's tableFooterView
property.
However, table footers (section footers AND table footers) are both built to scroll with your table. If you are looking to implement a "footer" that sticks to the bottom of the screen and does not scroll with the table, your best bet is to resize your UITableView
smaller to make room for your "footer", and add a new view to sit in the spot you just cleared for it. That way, it will stick in place, and the scrollable region in your table will not overlap with the "footer".