I actually create a UIScrollView
with a UITableView
inside it with interface builder. I set the content size of my UIScrollView
with:
scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
and I set my file's owner view to the UIScrollView
I created an IBOutlet
UITableView
and I set it in the interface builder.
When the view is loaded. it displays the correct content size for my UIScrollView
. But it doesn't display the correct content size for my UITableView
. Besides when I change the content size of my UIScrollView
, it changes the content size of my UITableView
as if both content size were related.
Anyone knows how can I keep the content size of my table view that I set in the interface builder?
A
UITableView
is aUIScrollView
. There are very few times when it would be useful to embed aUITableView
inside aUIScrollView
.Assuming you really do want this, you'll need to do the following somewhere. Probably in your
UIViewController
in methods likeviewDidAppear:
or somewhere you after you populate the table view.Example to dynamically manage the TableView Height along with ScrollView, works in Swift:
References to:
Call below method multiple times. Each time you call there will be more cells.
If you're still having problems, try this without the need for a scrollView.
After playing around with DBD's example for awhile, I found that the frame and contentSize don't seem to be able to be set together like:
The attempt was to set a max height of the frame but keep the ability to scroll though all of the content if there were a large number of cells. This hack seems to work well and can be modified with more conditions if needed:
This works for sure. You might need to adjust the autoresizingMask inside your .xib or in your code, but this hack is the only solution I found that takes care of all the different variables in my case.