一個簡短的問題,如果我可以,任何人都可以解釋我在下面丟失什麼,我假設第三個將工作?@property代表?
@interface ...
// These work
@property(assign) SomeClass *someDelegate;
@property(assign) id someDelegate;
// This gives warning
@property(assign) id <SomeClassDelegate> someDelegate;
。
@implementation ...
@synthesize someDelegate;
[self setSomeDelegate:[[SomeClass alloc] init]];
[someDelegate setDelegate:self];
。
warning: method '-setDelegate:' not found (return type defaults to 'id')
EDIT_001:
// SomeClass.h
#import <Foundation/Foundation.h>
@class SomeClass;
@protocol SomeClassDelegate <NSObject>
@optional
-(void)didHappen:(SomeClass *)someClass;
@required
-(void)willUse:(SomeClass *)someClass withThis:(BOOL)flag;
@end
@interface SomeClass : NSObject {
id <SomeClassDelegate> delegate;
}
@property(assign) id <SomeClassDelegate> delegate;
-(void)otherActions;
@end
歡呼加里。
這裏有沒有足夠的代碼SomeClass是什麼?SomeClassDelegate的定義是什麼?你會得到什麼警告? – deanWombourne 2010-06-22 15:01:23
新增SomeClass.h,@synthesize和警告: – fuzzygoat 2010-06-22 15:15:53
我知道這是一個很好的答案,但我不能確切地得到它適合我的問題 – Morkrom 2013-05-30 22:07:54