2

I'm working on a application where I have a UITableView inside a UIScrollview.

The TableView will display current games players are in, its inside a UIScrollView. I dynamically add cells to the UITableView for each game, but when I scroll the UIScrollView, the tableview inside it snaps back to its size set in the storybuilder.

This is because of autolayout, when I disable it, it doesn't happen anymore. However I do like autolayout for other views in my app. So my question is, how can I fix this problem?

Maybe someone can help me get on the right track.

Thanks

EDIT

I think I must explain my situation more, I will use an image where I can display what is happening

Explanation

Before and after scrolling.

As you can see I use the scrollview because there can be many games, so you'll have to scroll down to see them all. The TableView is just to hold the data, scrolling is disabled on that. After scrolling the TableView that says "JOUW BEURT" snaps back to its size set in the Storybuilder. This is because of auto layout like I said, but I don't know how to fix this.

Gavin
  • 35
  • 5
  • An `UITableView` is an `UIScrollView`. Do you have anything other than the `UITableView` in the `UIScrollView`? If not, you're adding an unneeded view. If you do, what are your constraints and/or relevant code? – jcaron Dec 28 '15 at 00:37
  • Add some screenshots will be better. – ImWH Dec 28 '15 at 06:19
  • Any luck @Gavin with my answer? – Joe Benton Dec 28 '15 at 10:25
  • @Gavin, did you find a solution to have a tableview inside a scrollview and make the frame (or contentSize) of tableview not change? I'm still having that problem. – Rodrigo Ruiz Apr 26 '16 at 05:50

3 Answers3

1

Why did you place UITableView inside UIScrollView?
Check below

  1. Check your constraints of UITableView and UIScrollView
  2. Placing UITableView inside UIScrollView is somewhat strange

EDIT You will just need to remove the scrollview and enable scrolling feature of the tableview. that will fix it

Soohwan Park
  • 625
  • 4
  • 11
1

You shouldn't put a tableview inside a scrollview as a tableview itself contains a scrollview and causes issues just like you are seeing when you have a scrollview inside a scrollview.

Remove the scrollview and this should fix your issue. If you are wanting to put content above the tableview or where you scroll down to view the tableview cells etc, consider adding a tableview header view that is added above the tableview.

Joe Benton
  • 3,703
  • 1
  • 21
  • 17
  • Yes remove the extra scroll view and make the whole screen a table view. Then add your two buttons as a table view header view which will be put above the whole table view. Then as you scroll down it will look as you wish and won't have the scrolling issues. – Joe Benton Dec 28 '15 at 11:26
  • Allright I'll try that, and accept your answer ones I got it to work. Thanks for the tip ;) – Gavin Dec 28 '15 at 11:28
  • No problem, glad I could help – Joe Benton Dec 28 '15 at 11:29
  • If you need help adding a table view header view you can do it in storyboard by dragging a uiview above the tableview (http://stackoverflow.com/questions/7841167/table-header-views-in-storyboards) or programmatically – Joe Benton Dec 28 '15 at 11:30
  • What if I want a scroll view with multiple table views? The scroll view scrolls horizontally and the table views vertically. – Rodrigo Ruiz Apr 26 '16 at 05:47
0

UITableView is already a subclass of UIScrollView

Zumry Mohamed
  • 9,318
  • 5
  • 46
  • 51