Search code examples
iosuitableviewstoryboard

How to let the tableview control fit the entire screen


I add a TableView to a new Single View Application. The exercise requires me to allow the TableView control to fit the entire screen. But I can't find any function to do this. Should I adjust the parameters in the Table View in Size Inspector?

enter image description here


Solution

  • You really should learn auto-layout and constraints as they're an extremely important part of building up layout in UIKit.
    For now, this is how you set your table view (or essentially any view) to fill the screen:

    1. Select your table view
    2. Click on the Add New Constraint button at the bottom right of your storyboard.
    3. Set 0 for top, bottom, left and right.

    That will add 4 constraints that will stretch your table view to fill up all the space available in the screen's safe area.

    e.g.