in my MainViewController I have a scrollView
and add a ChildView
in it which works fine. In this example I instantiate my PlansViewController2
and add it as a ChildView
to my scrollView
.
After selecting a Cell
it pushes a new controller. But I want to add the new Controller as a ChildView
to my `scrollView.
@IBAction func planAction(_ sender: UIButton) {
let newPlan = sender.frame.origin.x
scrollView.subviews.forEach{$0.removeFromSuperview()}
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let nextController = storyBoard.instantiateViewController(withIdentifier: "PlansViewController2") as! PlansViewController2
addChildView(viewController: nextController, in: scrollView)
self.movingView.frame.origin.x = newPlan
}
Im my PlansViewController2
I push another ViewController
but I want to add it also in my scrollView
from the previous controller.
let storyBoard = UIStoryboard(name:"Main", bundle:nil)
let planViewCtrl = storyBoard.instantiateViewController(withIdentifier: "PlanViewCtrl") as! PlanViewController
planViewCtrl.navigationItem.title = plan.title
self.show(planViewCtrl, sender: self)
_ = planViewCtrl.view // force view loading, so we can set it up properly
_ = self.updateLastUsed(plan: plan)
planViewCtrl.plan = plan
Is it possible to add - in my case here - the PlanViewController
into my scrollView
from my MainViewController
?
When you add view's PlansViewController2 to scrollview. Please add PlansViewController2 to childViewController of VC has scrollView(self.addChild(nextController)
).
When you want to add PlanViewController to scrollView:
parent
property (self.parent
).Good luck!