title: iOS (cs193p): Why are my UISplitViewControllerDelegate delegate methods not called on orientation change?
body: <p>I'm following the awesome Stanford cs193p course on iTunes and I'm now at lecture #7 and homework #3.</p>
  
  <p>I'm just trying to make the SplitViewController works correctly on iPad... but it looks like my UISplitViewControllerDelegate delegate methods are not called when the orientation of the device changes.</p>
  
  <p>Here's what I got so far:</p>
  
  <p>-I created a brand new iPad Storyboard, added a SplitViewController with a UIViewController as the Master (CalculatorViewController) and another UIViewController as the Detail (GraphViewController).  I think I did everything correctly.</p>
  
  <p>-My GraphViewController.h implements the UISplitViewControllerDelegate protocol:</p>
  
  <pre><code>@interface GraphViewController : UIViewController &lt;UISplitViewControllerDelegate&gt;
  </code></pre>
  
  <p>-My GraphViewController.m sets the SplitViewController delegate to itself:</p>
  
  <pre><code>- (void)awakeFromNib {
      [super awakeFromNib];
      self.splitViewController.delegate = self;
  }
  </code></pre>
  
  <p>-My GraphViewController.m implements the necessary methods:</p>
  
  <pre><code>// asks the delegate whether the first view controller should be hidden for the specified orientation
  - (BOOL)splitViewController:(UISplitViewController *)svc 
     shouldHideViewController:(UIViewController *)vc 
                inOrientation:(UIInterfaceOrientation)orientation
  {
      // only show the master controller in landscape mode
      return UIInterfaceOrientationIsPortrait(orientation);
  }
  
  // tells the delegate that the specified view controller is about to be hidden (must add a popover button)
  - (void)splitViewController:(UISplitViewController *)svc 
       willHideViewController:(UIViewController *)aViewController 
            withBarButtonItem:(UIBarButtonItem *)barButtonItem 
         forPopoverController:(UIPopoverController *)pc
  {
      barButtonItem.title = aViewController.title;
  
      // add the button to the toolbar
      NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
      [toolbarItems insertObject:barButtonItem atIndex:0];
      self.toolbar.items = toolbarItems; 
  }
  
  // tells the delegate that the specified view controller is about to be shown again (must remove popover button)
  - (void) splitViewController:(UISplitViewController *)svc 
        willShowViewController:(UIViewController *)aViewController 
     invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
  {    
      // hide the bar button item on the detail controller
      NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
      [toolbarItems removeObject:barButtonItem];
      self.toolbar.items = toolbarItems;
  }
  </code></pre>
  
  <p>-My GraphViewController.m supports all orientations:</p>
  
  <pre><code>- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
  {
      return YES; // support all types of orientation
  }
  </code></pre>
  
  <p>Now, when I run the application (Xcode 4.2 on Snow Leopard, iOS 5.0, iPad Simulator 5.0), the splitViewController:willHideViewController:withBarButtonItem:forPopoverController: method is called, my Master view is hidden and a button is shown in my Detail view to display the Master view in a PopOver (cause I'm in portrait mode).</p>
  
  <p>However, when I change the orientation of the device (to landscape mode... still using the simulator), nothing happens, none of the above methods get called again.  I end up with the Master view still hidden and the PopOver button still displayed, when in fact, I would like the Master view to be displayed and the PopOver button to be hidden.</p>
  
  <p>What am I doing wrong?
  Is this a problem with my code, with Xcode, with the simulator?</p>