so I have a viewcontroller that I put a scrollview in. Inside the scrollview, I put a bunch of items in the top half, like an image, labels, and buttons. On the bottom half, I put a uitableview. I set all the constraints and everything. I used the following code:
let bounds: CGRect = UIScreen.main.bounds
let w:Int = Int(bounds.size.width)
let h:Int = Int(chaptersTableView.contentSize.height)
let temp: Int = 300 + h
scrollView.contentSize = CGSize(width: w, height: temp)
chaptersTableView.frame = CGRect (x: 0, y: 280.5, width: self.view.frame.size.width, height: CGFloat(44 * sampleModel.objectChapterList.count))
I wanted to set the contentsize of the scrollview, and then set the height of my tableview frame.
The tableview is meant to contain many items, so I want the user to be able to scroll down, and the entire contents of the scrollview to scroll down to reveal more of the tableview. However, the tableview always gets cut off and when I scroll down in the scrollview, the table ends. I have to scroll inside of the tableview to access more cells.
Even when I replace the "44 * (number of cells in my table)" with a random number like 100, it will at first cut the table off so that is it short, but then when I tap the screen, the table will change to resume being full length to the bottom of the screen (but not to bottom of scrollview).
I thought about making all the stuff in the top half of the scrollview just another cell of the tableview so that it can be part of the table and I can avoid this hassle, but that would be a lot of work so I wanted to see if I could do this.
If you need pictures or something, I can provide them. If I'm not being clear, make sure to comment and I can explain better.
I suggest you to use tableView only. You can create your top view in the header of tableView. Doing this there will be no need to maintain the content size of scrollView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With