title: Using Storyboard Segues with Segmented Control
body: <p>I have a Segmented Control that I'm using to switch between three view controllers. My first tableview is embedded in a navigation controller where the segmented control is in the navigation controller. I also have two custom segues in the storyboard (with animations coming from the left and right). In my "main" controller class - the middle of the segmented control - I use this code </p>
  
  <pre><code>- (IBAction)indexChanged:(id)sender {
      if ([sender selectedSegmentIndex] == 0) {
          [self performSegueWithIdentifier:@"leftSegue" sender:self];
      }
      else if ([sender selectedSegmentIndex] == 1){
      }
      else {
          [self performSegueWithIdentifier:@"rightSegue" sender:self];
      }
  }
  </code></pre>
  
  <p>This works great for those two controllers. When those view controllers are put on the screen, I can still move between the far left and right controllers, but going back to the main controllers is crashing under each attempt I've tried. I think it has to do with me not understanding either the <code>self</code> that I'm sending the <code>performSegueWithIdentifier</code> message or <code>self</code> that I'm passing to <code>sender:</code>. </p>
  
  <p>Example: If in the <code>else if ([sender selectedSegmentIndex] == 1){}</code> I create a new segue, with a unique identifier coming from either of the two new controllers, the application crashes saying "Receiver has no segue with identifier" when it is spelled correctly. Who is the receiver in this example?</p>
  
  <p>Edit: I've added my current storyboard pictures here. The top two are the custom segues, and the middle two are modal and push, specific for the requirements. </p>
  
  <p>Edit2: Using methods like <code>self.navigationController.viewControllers[0]</code> finds the correct view, but it doesn't allow me to switch back to the initial controller- it redraws it an loses the navigation bar.</p>
  
  <p><img src="https://i.stack.imgur.com/LN3RL.png" alt="">
  <img src="https://i.stack.imgur.com/p6zql.png" alt=""></p>