title: Passing Values Between Master and Detail in UISplitViewController Using Storyboards
body: <p>I have defined the protocol in Customer.h file which is shown below: </p>
  
  <pre><code>@class Customer; 
  @protocol CustomerDelegate &lt;NSObject&gt;
  
  -(void) didSelectCustomer:(Customer *) customer; 
  
  @end
  
  @interface Customer : NSObject
  {
  
  }
  
  @property (nonatomic,copy) NSString *name; 
  @property (nonatomic,copy) NSString *occupation; 
  
  @end
  </code></pre>
  
  <p>The MasterViewController (left side) invokes the didSelectCustomer method as shown below: </p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      Customer *selectedCustomer = [customers objectAtIndex:[indexPath row]];
      [self.delegate didSelectCustomer:selectedCustomer]; 
  }
  </code></pre>
  
  <p>Now, I need to tell the DetailViewController (right side) to do something. The DetailViewController complies with the CustomerDelegate protocol. </p>
  
  <pre><code>@interface DetailViewController : UIViewController&lt;UISplitViewControllerDelegate,CustomerDelegate&gt;
  {
  
  }
  
  -(void) didSelectCustomer:(Customer *)customer
  {
      NSLog(@"sssdasdasdasd");
  }
  </code></pre>
  
  <p>The didSelectCustomer method is never invoked. I think I need to set the masterViewController.delegate = self but I am not sure where to set this thing up. </p>
  
  <p><strong>UPDATE 1:</strong> </p>
  
  <p>I added the instance of MasterViewController inside the DetailViewController but it did not work: </p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];    
  
      MasterViewController *master = [[MasterViewController alloc] init];
      master.delegate = self; 
  }
  </code></pre>
  
  <p><strong>SOLUTION:</strong> </p>
  
  <p>In AppDelegate:</p>
  
  <pre><code>  else 
      {
          UISplitViewController *splitViewController = (UISplitViewController *) self.window.rootViewController; 
          splitViewController.delegate = [splitViewController.viewControllers lastObject];
  
  
  
          UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
         // splitViewController.delegate = (id)navigationController.topViewController;
  
  
  
  
          DetailViewController *detail =(DetailViewController *) [splitViewController.viewControllers lastObject];
  
          UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0];
  
          MasterViewController *master = (MasterViewController *)masterNavigationController.topViewController;
  
          master.delegate = detail; 
      }
  </code></pre>