title: Swift - Use segmented control to navigate to different view controllers
body: <p>I've got an app with a mapViewController embedded in a navController. In the mapVC ive got a single bar button item which when clicked I want to conditionally "push" segue to one of a number of different view controllers. To achieve that ive set up an ibaction on the button and have the conditional "performSegueWithIdentifier" code in the relevant buttons ibaction method ie </p>
  
  <pre><code>    @IBAction func addButtonClicked(sender: UIBarButtonItem) {
      let lastAdd = "addItem"
      if lastAdd == "addItem"{
          self.performSegueWithIdentifier("addItem", sender: self)
      } else {
          self.performSegueWithIdentifier("addEvent", sender: self)
  
      }
  }
  </code></pre>
  
  <p>this will take me to either the addItemVC or the addEventVC. in each of those viewControllers (ie the addItemVC and the addEventVC) I want to have a segmented control in the navigation bar which, when clicked, will take me to the alternative VC ie if addItemVC is currently displayed, and the addEvent section of the segmented control is clicked, I want to display the addEventVC. Im following <a href="http://redartisan.com/2010/6/27/uisegmented-control-view-switching-revisited" rel="nofollow">Red Artisans page</a> on how to do this but in his example he is instantiating all view controller options upfront in the app delegate and so can easily get reference to each view controller and link it to the clicked segement of the segmented control within his rootVC</p>
  
  <p>Where im confused is .. seeing Im using conditional code before performing each segue, i assume that im only instantiating one viewController at a time when the bar button item is pressed. So how can i get an array of view controllers to pass to the VC im segueing to so that i can create the required segmented control in that VC. I assume i could manually create the destination VC array in my mapViewController and pass these across but wouldnt that mean im instatiating a different instance to the ones automatically created by the segue process?</p>