sarah
sarah

Reputation: 1221

how to make a space at the bottom of a UITableView in a UITableViewController

I want to add a footer to the UITableView, there are two ways, either footer for the section, or footer for the UITableView. Both don't work for me because I want to footer always at the bottom of the screen. In other words, floating footer.

That's why after searching, people suggest to but the footer under the UITableView. I would need to resize the UITableView and add the footer through IB under it. That makes sense and that's what I am asking for.

Kindly I have a specific problem and It's not about footer at all

My problem is that I couldn't create constrains for the UITableView that locates inside UITableViewContoller, whenever I click Ctrl + drag, I don't see the options that I would normally see.

Is that because I'm working with UITableViewController?

This is a screenshot of my hirechy

enter image description here

Again I would like to resay that my problem is not about footers, my problem is about how to resize the UITableView in a UITableViewController

Upvotes: 2

Views: 1065

Answers (3)

Rashwan L
Rashwan L

Reputation: 38833

I created a sample project with a fixed footer. You can download it here. What I have added is:

ContainerView 100%
- TableView 90% of the ContainerView and constraints to the ContainerView
- View 10% of the ContainerView and constraints to the ContainerView

enter image description here

Upvotes: 4

deltashade
deltashade

Reputation: 386

Yes, you are correct. You cannot add a footer on a UITableViewController. For this I recommend using a UIViewController.

Follow these steps if you want to add a footer:

  1. create UIViewController
  2. Add footer to the bottom and add constraints to the bottom border.
  3. Add UITableView to the UIView, and add constraints to the footer.

Also for the controller, just create two classes within the same file, and make one of them as a UITableViewController and the footer as regular class within the file.

If you just want space you should just use UIViewController. Add UITableView inside that, and put constraints on that.

This is one approach, and there maybe many other. Please let me know if I can help you any further.

Upvotes: 1

Michaël Azevedo
Michaël Azevedo

Reputation: 3896

You shouldn't resize the UITableView of an UITableViewController object : your tableview is in fact your main view. If you want to put a empty space that can't be scrolled below an UITableView, you should use an UIViewController instead.

Add an UITableView and an UIView to this UIViewController object. Set the left, right, and bottom constraints aligned to its superview for the UIView, and fix its height with a fourth constraint. Add the left, right and top constraints aligned to its superview for the UITableView, and set the vertical space between the view and the tableview to 0 with a constraint.

Upvotes: 1

Related Questions