我的問題是當我通過委託調用協議方法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