Question

I have read a lot of SO question about this already but nothing seems to work in my case. Simply when you add a UITableView and you test it and rotate the screen it will keep the width of the portrait orientation.

How can I make it so that it will always fill the screen's width for any screen size?

enter image description here

EDIT : My size inspector

enter image description here

Was it helpful?

Solution

Use the Autosizing feature in Storyboard for your UITableView. How to set it:

1.Select your UITableView.

2.Open the right pane -> Size Inspector:

enter image description here

3.Scroll down to the View section, here you'll see the Autosizing menu:

enter image description here

  1. Don;t forget to disable Autolayout feature:

enter image description here

OTHER TIPS

You're using AutoLayout in your XIB, so the AutoResizingMask stuff isn't your best route to success. You need to set the autolayout constraints on your TableView so that there is a 0 px gap between the leading (left) and trailing (right) sides of the TableView and its superview.

You can see from your screenshot that you already have some constraints in place, but they're probably not correct. I suggest you start by resetting all the existing constraints: I find that's usually best when I've got confused about where I am with constraints.

  1. Select the top level view in your XIB file
  2. Select Editor -> Resolve Auto Layout Issues -> Clear All Constraints in View from the menu
  3. Select your TableView
  4. Select Editor -> Resolve Auto Layout Issues -> Reset to Suggested Constraints from the menu

If that does the trick for you, I'd advise that you spend some time getting familiar with AutoLayout and review the constraints generated: you can select and edit them in the size inspector. This is also a pretty good tutorial.

For custom views, I often add my constraints programmatically as it's really easy to keep track of them - they're much more visible than when they're built in IB. I use a set of categories, provided by another SO user, that you'll find here and they make the code very easy to read and maintain.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top