Delegation, how to set up hierarchy with a non-viewController
<p>So, I understand the basic example of delegates.  What I have is this:</p>

<pre><code>WebService (class to handle grabbing web data)
HomeViewController (home screen)
ProgressViewController (shows the progress of a long download modally for long downloads)
OtherViewController (another view controller that might make a quick network request)
</code></pre>

<p>Scenario 1: So from the home screen, they can make a download where we would then ask the web service to get the data, and show the progress if it's a long download.</p>

<p>Scenario 2: OtherViewController might need some simple information from the internet.  It asks the web service for that data, and updates that view.  </p>

<p>Currently, everything is handled with NSNotifications.  </p>

<p>Scenario 1 with NSNotification: home screen presents modal view controller, adds the ProgressViewController as a listener to the webservice, ProgressViewController updates its screen when needed.</p>

<p>Scenario 2 with NSNotification: other view controller gets registered as an observer of the web service in viewDidLoad, gets the callbacks when needed from the web service.</p>

<p>I was wondering if and how I could set this up through delegation.  I thought it might be better to have a WebServiceDelegate that could implement methods like:</p>

<pre><code>- (void)webService:(WebService *)webService didUpdateProgress:(double)progress;
</code></pre>

<p>The problem I see with this is, if my web service starts a request to download some large amount of data, currently, the home screen view controller will do:</p>

<pre><code>ProgressViewController *pvc = [[ProgressViewController alloc] initWithNibName:@"ProgressViewController" bundle:nil];
</code></pre>

<p>to present the view controller, and then it listens for the progress updates.  </p>

<p>I don't see how I would do it through delegation since I don't know where I would set the delegate property.  In the WebService, I need to do something like:</p>

<pre><code>self.WebServiceDelegate = progressViewController;
</code></pre>

<p>However, the progressViewController doesn't get created in the web service.  It gets created  on the homeViewController.  The only thing I have come up with so far is do something like:</p>

<pre><code>ProgressViewController *pvc = [[ProgressViewController alloc] initWithNibName:@"ProgressViewController" bundle:nil];
            pvc.progressViewControllerDelegate = [WebServiceManager sharedInstance];
            self.webServiceManagerProgressDelegate = pvc;

            NSDictionary *progressViewDict = @{ @"ProgressViewController" : pvc };
            [[NSNotificationCenter defaultCenter] postNotificationName:WebServiceShowProgressViewNotification object:self userInfo:progressViewDict];
</code></pre>

<p>Where the web service knows that it's supposed to show this view controller, posts the notification for that, and then whoever (in my case the home view) was listening, can show the progressViewController, and then the progressViewController can show the progress and respond to web service delegate methods.  It seems kind of roundabout and I didn't know if there was a better way to do this, or just stick with notifications.  Thanks!</p>
