David David - 5 months ago 17
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?


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.