Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want a UITableView inside of a UIScrollView to extend to the bottom of the UIScrollView and not get cut off by initial screen

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.

like image 548
Ethan Zhao Avatar asked Apr 10 '17 04:04

Ethan Zhao


1 Answers

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.

like image 117
Aashish1aug Avatar answered Sep 28 '22 00:09

Aashish1aug