title: What's the best way to communicate between view controllers?
body: <p>Being new to objective-c, cocoa, and iPhone dev in general, I have a strong desire to get the most out of the language and the frameworks.</p>
  
  <p>One of the resources I'm using is Stanford's CS193P class notes that they have left on the web.  It includes lecture notes, assignments and sample code, and since the course was given by Apple dev's, I definitely consider it to be "from the horse's mouth".</p>
  
  <p>Class Website:<br>
  <a href="http://www.stanford.edu/class/cs193p/cgi-bin/index.php" rel="noreferrer">http://www.stanford.edu/class/cs193p/cgi-bin/index.php</a></p>
  
  <p>Lecture 08 is related to an assignment to build a UINavigationController based app that has multiple UIViewControllers pushed onto the UINavigationController stack.  That's how the UINavigationController works.  That's logical.  However, there are some stern warnings in the slide about communicating between your UIViewControllers.</p>
  
  <p>I'm going to quote from this serious of slides:<br>
  <a href="http://cs193p.stanford.edu/downloads/08-NavigationTabBarControllers.pdf" rel="noreferrer">http://cs193p.stanford.edu/downloads/08-NavigationTabBarControllers.pdf</a></p>
  
  <p>Page 16/51:</p>
  
  <blockquote>
    <h1>How Not To Share Data</h1>
    
    <ul>
    <li>Global Variables or singletons
    
    <ul>
    <li>This includes your <strong>application delegate</strong></li>
    </ul></li>
    <li>Direct dependencies make your code less reusable
    
    <ul>
    <li>And more difficult to debug &amp; test</li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>Ok.  I'm down with that.  Don't blindly toss all your methods that will be used for communicating between the viewcontroller into your app delegate and reference the viewcontroller instances in the app delegate methods.  Fair 'nuff.</p>
  
  <p>A bit further on, we get this slide telling us what we <em>should</em> do.</p>
  
  <p>Page 18/51:</p>
  
  <blockquote>
    <h1>Best Practices for Data Flow</h1>
    
    <ul>
    <li>Figure out <strong>exactly</strong> what needs to be communicated</li>
    <li><strong>Define input parameters</strong> for your view controller</li>
    <li>For communicating back up the hierarchy, <strong>use loose coupling</strong>
    
    <ul>
    <li>Define a generic interface for observers (like delegation)</li>
    </ul></li>
    </ul>
  </blockquote>
  
  <p>This slide is then followed by what appears to be a place holder slide where the lecturer then apparently demonstrates the best practices using an example with the UIImagePickerController.  I wish the videos were available! :(</p>
  
  <p>Ok, so... I'm afraid my objc-fu is not so strong.  I'm also a bit confused by the final line in the above quote.  I've been doing my fair share of googling about this and I found what appears to be a decent article talking about the various methods of Observing/Notification techniques:<br>
  <a href="http://cocoawithlove.com/2008/06/five-approaches-to-listening-observing.html" rel="noreferrer">http://cocoawithlove.com/2008/06/five-approaches-to-listening-observing.html</a></p>
  
  <p>Method #5 even indicates delegates as an method!  Except.... objects can only set one delegate at a time.  So when I have multiple viewcontroller communication, what am I to do?</p>
  
  <p>Ok, that's the set up gang.  I know I can easily do my communication methods in the app delegate by reference's the multiple viewcontroller instances in my appdelegate but I want to do this sort of thing the <em>right</em> way.</p>
  
  <p>Please help me "do the right thing" by answering the following questions:</p>
  
  <ol>
  <li>When I am trying to push a new viewcontroller on the UINavigationController stack, <strong>who</strong> should be doing this push.  <strong>Which</strong> class/file in my code is the correct place?</li>
  <li>When I want to affect some piece of data (value of an iVar) in one of my UIViewControllers when I am in a <strong>different</strong> UIViewController, what is the "right" way to do this?</li>
  <li>Give that we can only have one delegate set at a time in an object, what would the implementation look like for when the lecturer says <em>"Define a generic interface for observers (like delegation)"</em>.  A pseudocode example would be awfully helpful here if possible.</li>
  </ol>