UITableView with dynamic height in Swift

620 Views Asked by At

I would like to create a dynamically sized UITableView in Swift. When I add a UITableView via the storyboard some content is cut off at a certain point.

Is there a way to make it possible to scroll through the content without cutting off any of it? I've thought about adding a UIScrollView, but this kind of view seems to be used for something else (e.g.: http://www.raywenderlich.com/76436/use-uiscrollview-scroll-zoom-content-swift )

At best I'd like to have a scrollable UITableView that almost fills the screen and a button that always stays on the very bottom.

Edit - To clarify what I meant by cutting off: When there are e.g. 100 elements in an array, only 10 were displayed.

But the concept of placeholder constraints solved this issue, since my array length is determined during runtime.

1

There are 1 best solutions below

0
Toldy On BEST ANSWER

To have a dynamically sized UITableView, use AutoLayout. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html

Yes its possible to not cut your content, but how is your content cutted ? Could you link a screenshot about it ?

You didn't talk about your constraints, did you set yours correctly ? For example, you can set them like that for :

  • UITableView: UITableView constraints
  • UIButton: UITableView constraints

UITableView is a subclass of UIScrollView, your link show a specific usage of UIScrollView options (Paging), but it is not the default behavior of this component. Here is an example: http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/