Voque
Voque

Reputation: 168

Embed view controller inside container view based on selection from tableview

I'm trying to change the content of my container view based on what has been chosen from TableViewController and I'm out of an idea.

The structure in my storyboard looks like this:

structure

Currently, my container view has embed segue with Table View and that's working great. Now after select something from Table View for example Map I want to display MapViewController inside container view and keep my header and footer. How can I do this?

Upvotes: 0

Views: 1453

Answers (1)

Syed Qamar Abbas
Syed Qamar Abbas

Reputation: 3677

First disable the segue form your container view to a DestinationViewController in your storyboard. Now load your viewController object based on your previous tableViewController selection.

//this controller will be change on tableView selection make your own logic here.
let controller = storyboard!.instantiateViewController(withIdentifier: "Second")
addChildViewController(controller)
//Set this value false if you want to set Autolayout programmatically or set it true if you want to handle it with `frame`
controller.view.translatesAutoresizingMaskIntoConstraints = false
containerView.addSubview(controller.view)
controller.didMove(toParentViewController: self)

Upvotes: 1

Related Questions