我的问题是当我通过委托调用协议方法dataLoading
时,它只是无法识别它 - 给出expected identifier
错误。协议方法在通过委托调用时不被识别
下面是协议/接口文件:
#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
这里是实现文件:
#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
的错误是在这一行:selector:@selector([self.delegate dataLoading])
我敢肯定,这是我的一个愚蠢的错误,但我不明白为什么它不认可这种方法,因为代表与协议绑定在一起...
卫生署!是的,因为我已经指定了目标!多么愚蠢的错误。 – xil3