I have a view controller which has a UISegmentControl with two buttons. I load this View and when the SegmentValue has changed i'll add a view controller into the view.
This is MainViewController
In the class I define the controllers
var tabNavigation: UISegmentedControl!
let viewController1:ViewController1 = ViewController1()
let viewController2:ViewController2 = ViewController2()
// Create the segment control
self.tabNavigation = UISegmentedControl(items: ["v1", "v2"])
self.tabNavigation.selectedSegmentIndex = 0
self.tabNavigation.frame = CGRectMake(60, 250, 130, 25)
self.tabNavigation.addTarget(self, action: "segmentedValueChanged", forControlEvents: .ValueChanged)
self.navigationItem.titleView = self.tabNavigation
// set first view
self.addChildViewController(viewController1)
self.view.addSubview(viewController1.view)
// Segement changed
func segmentedValueChanged() {
if (self.tabNavigation.selectedSegmentIndex == 0) {
self.addChildViewController(viewController1)
self.view.addSubview(viewController1.view)
} else {
self.addChildViewController(viewController2)
self.view.addSubview(viewController2.view)
In the storyboard i have a segue from MainViewController to ViewController3
Now in ViewController1 i'm trying to create a segue (should be part of a previous navigation controller so swipe across with a back button) from ViewController1 to ViewController3. But fails as the segue does not exist as ViewController1 is made completely from Code.
My code for the segue is below but obviously fails as that is the segue identifier for MainViewController to ViewController3
performSegueWithIdentifier("loadVC3", sender: nil)