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 3983202
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:37:09+00:00 2026-05-20T05:37:09+00:00

So, I have a decent idea of what a delegate does, why use it,

  • 0

So, I have a decent idea of what a delegate does, why use it, how to implement it etc. and I’m working on implementing it in one of my projects. The problem I’m trying to solve is to decouple my Controller objects from my Network Access class. In this context, the ideas get a little messy in my head.

I somehow intuitively feel that the NetworkAccessClass should be the delegate for a Controller object, because the NetworkAccessClass is acting as a helper for the Controller object. But it seems to work in a reverse fashion, because the following is apparently the right way to do it:

NetworkaccessClass.h

@protocol NetworkAccessDelegate
-(void) requestSucceded:(NSData *) data
-(void) requestFailed:(int) responseCode;
@end
@interface NetworkAccessClass : NSObject
{
    id<NetworkAccessDelegate> networkDelegate;
}

@property(nonatomic, assign) id networkDelegate;

-(void) initWithDelegate:(id) delegate; //

@end

NetworkAccessClass.m

@implementation
@synthesize networkDelegate

-(void) initWithParams:(id) delegate
{
    networkDelegate = delegate;
    // Assign GET/POST vals, create request etc
    [request startAsynchronous];    
}

-(void) requestSucceded:(ASIHTTPRequest *) request
{
    if([networkDelegate respondsToSelector:@selector(requestSucceded:)]) {
        // Send the data to the controller object for it to use
        ...
    }
}

-(void) requestFailed:(ASIHTTPRequest *) request
{
    // Same as above. Send to request failed.
}

@end 

And finally in my FirstViewController.h

#import "NetworkAccessClass.h"
@interface FirstViewController<NetworkAccessDelegate>
{

}
-(void) requestSucceded:(NSData *) data;
-(void) requestFailed:(int) responseCode;
@end

And the same in SecondViewController.h and so on.

Although this does decouple my Controllers from my Network class, I can’t help feel it’s wrong because the controllers in this case are acting as delegates or helper methods to the Network Class and not the other way round. Am I missing something basic? Or is this how it is?

Thanks,
Teja.

  • 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-05-20T05:37:10+00:00Added an answer on May 20, 2026 at 5:37 am

    Delegates aren’t “helper methods”. Think of them as objects that get notified when something happens. (Although don’t confuse them with “Notifications”–that’s a different thing entirely.) In this case, your network class does it’s stuff and then calls its delegate method on the View Controller that instantiated and fired, it to report the contents of that response to the view controller. The controller will then, presumably, update the view with the data that the network connector got. Classic delegate pattern, right there.

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

Sidebar

Related Questions

Does anyone have a decent algorithm for calculating axis minima and maxima? When creating
Does windows have any decent sampling (eg. non-instrumenting) profilers available? Preferably something akin to
I have a site that I've developed that makes decent use of Javascript, and
I have a decent idea in mind. I don't see a lot of stuff
Anyone have a decent example, preferably practical/useful, they could post demonstrating the concept?
If I have a decent size asp.net page open in Source view, and hold
I have seen this question: Are there any decent UI components for touch screen
I have scoured the web for a decent explanation of the routing syntax in
I have implemented what I thought was a pretty decent representation of MVC in
I have recently been exposed to naked objects. It looks like a pretty decent

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.