i'm trying to load a viewcontroller (with tableview) as a subview inside a contentview of a parent view controller and trying to get the height of the subview.
MainViewController:
- ScrollView (scrollable)
- ContentView
- HeaderView
- NavigationView
- SegmentedControl <- this triggers which viewcontroller to load
- MainContentHolder <- this is where viewcontrollers are loaded
- ContentView
- ScrollView (scrollable)
HistoryViewController:
- View
- TableView (unscrollable) - displays certain number of records
- TableViewCell
- UIView
- ImageView
- LabelView
- UIView
- View
in HistoryViewController, data are being fetched (using Alamofire), then populating the cells.
In "MainViewController", there is a "SegmentedControl". I'm loading viewcontroller using this code:
@IBAction func scIndexedChanged(_ sender: UISegmentedControl) {
switch segmentedControl.selectedSegmentIndex
{
case 0:
let vc1 = self.storyboard?.instantiateViewController(withIdentifier: "vc1") as! vc1Controller
vc1.view.frame = mainContentHolder.bounds
mainContentHolder.addSubview(vc1.view)
addChildViewController(vc1)
vc1.didMove(toParentViewController: self)
case 1:
let vc2 = self.storyboard?.instantiateViewController(withIdentifier: "vc2") as! vc2Controller
vc2.view.frame = mainContentHolder.bounds
mainContentHolder.addSubview(vc2.view)
addChildViewController(vc2)
vc2.didMove(toParentViewController: self)
case 2:
let vc3 = self.storyboard?.instantiateViewController(withIdentifier: "vc3") as! vc3Controller
vc3.view.frame = mainContentHolder.bounds
mainContentHolder.addSubview(vc3.view)
addChildViewController(vc3)
vc3.didMove(toParentViewController: self)
default:
break;
}
Questions:
How to get the actual contentSize of the loaded viewcontroller (subview) AFTER populating cells? (uses Alamofire)
How to adjust the height of the ScrollView and/or ContentView of MainViewController to accommodate the height of the loaded subview (TableView, CollectionView, View.Frame)?
What is the proper way of doing this?
I'm also adding additional data to the loaded VC with:
scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
from "MainViewController" and calling a function on the loaded VC to load more content after reaching a certain threshhold:
vc1.loadMoreContent()
Note: content size height is dynamically changing depending on how many NEW records are loaded.
Any help is very much appreciated
Thanks in advance