title: Switching ViewControllers with UISegmentedControl in iOS5
body: <p>I am trying something very simple but somehow I can't get it to work. All I try to do is switching between 2 View Controllers using an UISegmentedControl as you can see it for example in the App Store application in the Highlights tab.</p>
  
  <p>I am using iOS5 and Storyboards.</p>
  
  <p>Here's my Storyboad line up:</p>
  
  <p><img src="https://i.stack.imgur.com/bpoZ0.png" alt="enter image description here"></p>
  
  <p>So I have a root View Controller and two UITableViews - This 2 TableViews I want to switch.</p>
  
  <p>Here's how the implementation file looks like</p>
  
  <pre><code>#import "SegmentedLocationViewController.h"
  #import "PastEventsLocationViewController.h"
  #import "FutureEventsLocationViewController.h"
  
  @interface SegmentedLocationViewController()
  @property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedControl;
  @property (strong, nonatomic) NSArray *viewControllers;
  @end
  
  
  @implementation SegmentedLocationViewController
  
  @synthesize segmentedControl = _segmentedControl;
  @synthesize viewControllers = _viewControllers;
  
  - (IBAction)indexDidChangeForSegmentedControl:(UISegmentedControl*)segmentedControl
  {
      NSLog(@"index: %d", segmentedControl.selectedSegmentIndex);
  }
  
  - (void)setupViewControllers
  {
      PastEventsLocationViewController *pastEventsLocationViewController = [[PastEventsLocationViewController alloc] initWithStyle:UITableViewStylePlain];
      FutureEventsLocationViewController *futureEventsLocationViewController = [[FutureEventsLocationViewController alloc] initWithStyle:UITableViewStylePlain];
  
      self.viewControllers = [NSArray arrayWithObjects:pastEventsLocationViewController, futureEventsLocationViewController, nil];
  }
  
  - (void)setupUI
  {
      [self.segmentedControl addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged];
  }
  
  // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      [self setupViewControllers];
      [self setupUI];
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      return YES;
  }
  
  @end
  </code></pre>
  
  <p>I can trigger the switch event and can log the currently selected index. But I don't have any idea where to go from here.</p>
  
  <p>Maybe someone can turn my attention towards a certain direction...?</p>