1

My problem is that when I am calling the protocol method dataLoading via the delegate, it just doesn't recognize it - giving an expected identifier error.

Here is the protocol/interface file:

#import <Foundation/Foundation.h>

@class LoaderView;

@protocol DataLoaderProtocol <NSObject>

@required
- (void) dataLoading;
- (void) doneLoading;

@end

@interface DataLoader : NSObject {

}

@property (retain) id <DataLoaderProtocol> delegate;
@property (retain, nonatomic) LoaderView *loader;

- (id) initWithDelegate: (id <DataLoaderProtocol>) delegate;
- (void) start;

@end

And here is the implementation file:

#import "DataLoader.h"
#import "LoaderView.h"


@implementation DataLoader

@synthesize delegate = _delegate;
@synthesize loader = _loader;

- (id) initWithDelegate: (id <DataLoaderProtocol>) delegate
{
    self.delegate = delegate;

    return self;
}

- (void) start
{
    NSOperationQueue *queue = [NSOperationQueue new];
    NSInvocationOperation *operation = [[NSInvocationOperation alloc] 
                                        initWithTarget:self.delegate
                                        selector:@selector([self.delegate dataLoading]) 
                                        object:nil];
    [queue addOperation:operation]; 
    [operation release];
}

@end

The error is at this line: selector:@selector([self.delegate dataLoading])

I'm sure this is a stupid mistake on my part, but I don't understand why it's not recognizing that method, since the delegate is tied in with the protocol...

3 Answers 3

4

The way you wrote selector:@selector([self.delegate dataLoading]) is wrong try using : selector:@selector(dataLoading) instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Doh!! Yea you're right, because I already specified the target! What a stupid mistake.
1

I don't know if self is defined yet when you call initWithDelegate. That may be messing up things downstream...

Try:

- (id) initWithDelegate: (id <DataLoaderProtocol>) delegate {
    self = [super init];
    if(self) {
        self.delegate = delegate
    }
    return self;
}

1 Comment

right, and don't we need to make a direct assignement too ? delegate = [aDelegate retain];
1

You're passing a selector (i.e. SEL type), therefore you would need to write this:

NSInvocationOperation *operation = 
    [[NSInvocationOperation alloc] 
        initWithTarget:self.delegate
              selector:@selector(dataLoading) // the name of the selector here 
                object:nil];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.