-1

I have a table view that has scrolling disabled and I can add items to it. Above and beneath it are a few other controls. The problem is, when the table view gets too many items, the content is out of screen.

To solve this I think I need a scroll view but it needs to wrap the whole content and needs to be dynamic in height. How can I do this?

Edit: Maybe this makes the question simpler: I need to have a scrollView, that basically wraps the content. The content is a table View, that varies in height and some buttons.

Jonas
  • 7,089
  • 15
  • 49
  • 110
  • This will be a bad idea! – iPeter Jul 09 '18 at 15:35
  • `UITableView` is a `UIScrollView` subclass. It's not recommended to embed a `UIScrollView` within a `UIScrollView` because of the difficulty of managing the touch events. – particleman Jul 09 '18 at 15:36
  • I don't know if I have understand but look [here](https://developer.apple.com/documentation/uikit/uiscrollview/1619383-alwaysbouncevertical) – Kerberos Jul 09 '18 at 15:37
  • Why is this a bad idea? I have disabled the scrolling of the tableView, I want just the ScrollView to scroll so there is not "scrolling conflict"... – Jonas Jul 09 '18 at 15:55
  • @Kerberos Thanks but I don't think this is what I was looking for – Jonas Jul 09 '18 at 15:56
  • @Jonas setting the property to yes you can lock the scroll of the tableview only if all the cells are visible. – Kerberos Jul 09 '18 at 16:01
  • @Kerberos I already have locked the scrolling of the tableView. What I want to do is have a ScrollView, that wraps this tableView, so I can scroll this ScrollView instead of the tableView – Jonas Jul 09 '18 at 16:11
  • See https://stackoverflow.com/questions/17121488/how-to-use-uitableview-inside-uiscrollview-and-receive-a-cell-click for some reasons why this is a bad idea. – particleman Jul 09 '18 at 16:31

1 Answers1

0

i think you must make an autolayout try this steps 1- Set view constraint (top, bottom, leading and trailing) as (0,0,0,0). 2- Now you can see hierarchy like this view -> scroll view -> view(content view).

3- Now we need add more constraint for content view.

  • Most important step *

4 - Our content view must have equal width and equal height with parent view.

Now select height constraint of content view and set priority with low(250).

5- We are done with our setup. 6- Now you can design your view with any height.

N.aloraini
  • 21
  • 2
  • Im not sure If I understand you correctly. You mean a hierarchy like this: View -> Scroll View ->(Content View:) View -> (Content:)TableView and Buttons. Then the content View should have a height constraint? – Jonas Jul 09 '18 at 16:05
  • never use tableview inside scroll view – Wings Jul 09 '18 at 16:06
  • Can you say why I shouldn't do that? – Jonas Jul 09 '18 at 16:07
  • because apple say not to use ...according to apple guide lines, tableview shouldn't be added to scrollView. App may likely be rejected by apple. So its better if you only use tableview – Wings Jul 09 '18 at 16:18
  • Ah ok thats a good reason, thank you. But still how could I do it, so that for example a Button and a TextField scroll at once? – Jonas Jul 09 '18 at 16:55