I am trying to embed a table view into a scroll view. I would like the scrolling to happen on the scroll view level. I am able to embed the table view into the scroll view but I am stuck at trying to resize the scroll view content size to fit the full height of the table view..how can I achieve this?
Asked
Active
Viewed 827 times
1
-
Did you search SO yet? Quite a few answers. The answers given on this one: http://stackoverflow.com/questions/17121488/how-to-use-uitableview-inside-uiscrollview-and-receive-a-cell-click look legit to me – danh May 29 '15 at 15:03
-
It says that Apple advises against it but Instagram does it in their profile screen...I'm trying to mimic that @danh – Mike Simz May 29 '15 at 15:05
-
It may not mimic instagram exactly, but a UIPageViewController whose pages contain tables would provide the 2D scrolling effect that it sounds like you'd like. And its 100% kosher relative to how the sdk works – danh May 29 '15 at 15:08
-
1I don't think Instagram puts a table view in s scroll view. I think they either use a collection view or a regular old table view and set the header to be the info at the top of the profile. You'll have a much better experience if you go that direction. – gurooj May 29 '15 at 15:20
-
I think you're right @gurooj !! After taking a second look at it that does make much more sense – Mike Simz May 29 '15 at 15:33
-
1@MikeSimz you'll have much better scrolling performance if you use the header or footer of a table view or collection view. Or just make the first cell be different and contain the header view inside a regular cell. Both classes are very flexible for this use case. – gurooj May 29 '15 at 15:38
2 Answers
0
you can calculate tableview height in heightForFooterInSection
or viewForFooterInSection
of table
_tblOption.scrollEnabled = NO;
Frame = _tblOption.frame;
Frame.size.height = _tblOption.contentSize.height;
_tblOption.frame = Frame;
_mainScrollView.contentSize = CGSizeMake(_mainScrollView.contentSize.width, _tblOption.frame.origin.y + _tblOption.contentSize.height);

Aanabidden
- 375
- 6
- 18
0
Your hierarchy should be as follow: UIView
-> UIScrollView
-> UITableView
. That mean you simple create UIViewController, then place UIScrollView, connect delegates and so forth, then place in it UITableView controller.
But im wonder why would you put tableView
inside scroll view, better design would be place separately UITableView
and UIScrollView
.
I much rather recommend you to have UIView with UITableView AND UIScrollView, placed separately.
In XCode you may use Editor->Embed In.

Evgeniy Kleban
- 6,794
- 13
- 54
- 107
-
I want it like this because this is how Instagram designed their Profile screen by the looks of it. – Mike Simz May 29 '15 at 15:18
-
Okay, there is UIScrollView + UICoillectionView and UIScrollView + UITableView, but their are placed separately as i told you. – Evgeniy Kleban May 29 '15 at 15:20
-
I don't believe they are placed separately because they scroll all as one..nonetheless, after taking another look I believe it is just a single table view and the personal info at the top is simply the header of the table view – Mike Simz May 29 '15 at 15:34
-
@MikeSimz ok, please check this project (its not mine though) and go through implementation of Views (when i made my instagramm app i place it separately as well ) - https://github.com/8ofproject/ElPhotoSnooper – Evgeniy Kleban May 29 '15 at 15:36