Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8360521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:29:17+00:00 2026-06-09T11:29:17+00:00

So, I understand the basic example of delegates. What I have is this: WebService

  • 0

So, I understand the basic example of delegates. What I have is this:

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)

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.

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

Currently, everything is handled with NSNotifications.

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.

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.

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:

- (void)webService:(WebService *)webService didUpdateProgress:(double)progress;

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:

ProgressViewController *pvc = [[ProgressViewController alloc] initWithNibName:@"ProgressViewController" bundle:nil];

to present the view controller, and then it listens for the progress updates.

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:

self.WebServiceDelegate = progressViewController;

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:

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];

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:29:18+00:00Added an answer on June 9, 2026 at 11:29 am

    If I understand your situation correctly, homeViewController has a reference to the web service, and then homeViewController creates an instance of ProgressViewController. Then ProgressViewController needs to get updates from that web service using delegation. You could try something like this as part of HomeViewController:

    ProgressViewController *pvc = ProgressViewController *pvc = [[ProgressViewController alloc] initWithNibName:@"ProgressViewController" bundle:nil];
    self.webService.delegate = pvc;
    

    Of course, this requires homeViewController to have a reference to WebService (I called this webService).

    Where the web service knows that it’s supposed to show this view controller

    It really shouldn’t know about any of that. It just needs to do its thing (download, upload, whatever), and if there’s something to report, it does so by sending its delegate a message. That delegate (whoever that may be), will then update views accordingly.

    EDIT: I just realized that WebService is a singleton. I believe the preferred approach for singletons is actually using notifications. Since all view controllers can access a singleton, delegation isn’t always an option as all these view controllers may need an update on what’s going on, while the object can only have one delegate. If only one or two view controllers use the WebService singleton, you should probably not make it a singleton.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand this is a basic question... but I have been stuck on it
I'm trying to understand why this does not work. (Basic example with no validation
I've started with very basic example in order to understand how to read data
For the life of my I can't understand how the basic paperclip example works.
I have been looking for very basic keyword driven test..i do not understand well
Something basic that i don't understand: I have header.php with navigation bar for my
I am trying to understand Nokogiri. Does anyone have a link to a basic
I am trying to better understand basic concepts in OOP. What are static and
So I understand the basic techniques that are used in branch prediction for pipelined
I think I understand the basic principals of T4 but I'm having a hard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.