Tom Fox
Tom Fox

Reputation: 905

Is it possible to have a 'sticky' footer on a UITableViewController?

I'm trying to build a checkout screen allowing the user to enter card details etc. I want to have 'buy with Apple Pay' or 'other' buttons pinned to the bottom of the UITableViewController so they are easily visible at all times.

I'm aware that this would be possible with a UITableView nested in a UIViewController but I'm just wondering if a similar result is possible using UITableViewController?

Here is a screen recording of the Apple Store app showing the desired behaviour. (expires 18th August)

Upvotes: 1

Views: 4316

Answers (5)

Cemal BAYRI
Cemal BAYRI

Reputation: 410

You can do it by adding a extra view on tableview controller ui view controller view. You have to get attention view hierarchy for that.

Upvotes: 0

Aravind Vijayan
Aravind Vijayan

Reputation: 155

tableFooterView will only be visible after that last cell. Out of the box solution is not available for this issue. If you are adding section footer you will face two possible issues i.e if you have more than one section and when the content is less than the height of tableview. Only possible solution is adding a UIView above your tableview.

Upvotes: 0

Maarut
Maarut

Reputation: 108

It might be worth moving the UITableViewController in to an embedded view. That way you can have whatever you like overlay the bottom of the table view.

Upvotes: 0

Tom E
Tom E

Reputation: 1607

There are many reasons for not using a UITableViewController and using a regular UIViewController with a table view added manually to it—this is one of them. Actually, the only real reason for a UITableViewController is when you want to have static cells instead of dynamic prototypes.

Upvotes: 0

Sanjukta
Sanjukta

Reputation: 1055

You can use table view datasource method like:

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    // Write your code for sticky design 
}

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 100
}

It may helps you.Thank you.

Upvotes: 1

Related Questions