我想爲NSWindow
創建自定義代理。 CustomWindow被分類以獲得關於NSWindowDelegate
事件的通知。 現在我想爲此CustomWindow
創建delegate
。NSWindow的自定義代理
我嘗試下面的代碼:
CustomWindow.h
@class CustomWindow;
@protocol CustomWindowDelegate
- (void)method1:(CustomWindow *)sender userInfo:(NSMutableDictionary*) userInfo;
- (void)method2:(CustomWindow *)sender event:(NSEvent *)theEvent;
- (void)method3:(CustomWindow *)sender;
@end
@interface CustomWindow : NSWindow <NSWindowDelegate>
@property (nonatomic) id <CustomWindowDelegate> delegate;
@end
mainDocument.h
#import "CustomWindow.h"
@interface mainDocument : NSDocument
@property (assign) IBOutlet CustomWindow *mainWindow;
@end
mainDocument.m
#import "mainDocument.h"
@implementation mainDocument
- (void)method1:(CustomWindow *)sender userInfo:(NSMutableDictionary*) userInfo
{
...
...
}
- (void)method2:(CustomWindow *)sender event:(NSEvent *)theEvent
{
...
...
}
- (void)method3:(CustomWindow *)sender
{
...
...
}
@end
其按預期工作howeve ř其給予以下警告:
「保留(或強)」屬性上屬性「委託」從屬性「委託」「NSWindow」
「原子」屬性繼承的屬性不匹配不匹配從「NSWindow」
房產類型的「id」繼承屬性是與類型不兼容「身份證_Nullable」從「NSWindow」
自動屬性合成將不能合成屬性「委託」繼承;它將通過它的超類實現,使用@dynamic來確認意圖
我該如何擺脫這些警告?
任何幫助,非常感謝。
謝謝。 '_one的第二個選項可以將一個新的委託協議與'NSWindowDelegate'結合使用,並重新使用現有的委託屬性_'爲我工作 – Amrita