我的问题是当我调用协议(protocol)方法时 dataLoading
通过委托(delegate),它只是无法识别它 - 给出 expected identifier
错误。
这是协议(protocol)/接口(interface)文件:
#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])
我确信这是我的一个愚蠢的错误,但我不明白为什么它不能识别该方法,因为委托(delegate)与协议(protocol)绑定(bind)......
最佳答案
你写的方式selector:@selector([self.delegate dataLoading])
尝试使用是错误的:selector:@selector(dataLoading)
反而。
关于objective-c - 通过委托(delegate)调用时无法识别协议(protocol)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6666857/