David David - 1 year ago 114
Swift Question

Switch to another ContainerView from inside a ContainerView

I made an iOS app with Xcode and Swift.

One ViewController contains two ContainerViews. The user can switch between them with SegmentedControl.

But, how can I switch to the other ContainerView without the SegmentedControl, e.g. with a button?

Actually I have this code:

let vc : AnyObject! = self.storyboard!.instantiateViewControllerWithIdentifier("login")
self.showViewController(vc as! UIViewController, sender: vc)

This opens the other ContainerView, but as single VC, not inside the parent ViewController.

What can I do to reach the other ContainerView shown in the parent VC?

Answer Source

You must have to set the IBoutlets from ContainerViews viewControllers too to call them separately using uibuttons action.

assign same class to both parentViewcontroller and containerView using identity inspector see image.

enter image description here

connect IBOutlet as well like parentViewController see image

enter image description here

Now can access from class using uibutton action.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download