0
My Cocoa AppDelegate包含對其主視圖的類型ID的引用。該引用是多態的,因爲它可能指向PDFView的子類或NSImageView的子類,具體取決於視圖圖像的來源。這兩個視圖子類都實現相同的協議,所以我的AppDelegate不必知道它處理的是什麼類型的視圖。但是,每次我調用其中一種協議方法時,我都會收到一條警告,指出「實例方法'-methodName'找不到(返回類型默認爲'id')」。我可以忽略警告或通過使用「performSelector:(@ selector(methodName :))」來調用協議方法來強制執行此問題。避免找不到協議方法的方法
有沒有我可以做的(或應該做的)訴諸performSelector
//FLAppDelegate.h
@interface FLAppDelegate : NSObject <NSApplicationDelegate>
{
...
IBOutlet id _formImageView; //type is FLPDFView* or FLImageView*
…
}
//FLFormImageProtocol.h
@protocol FLFormImageProtocol <NSObject>
@required
- (void) methodName;
@end
//FLPDFView.h
@interface FLPDFView : PDFView <FLFormImageProtocol>
@end
//FLImageView.h
@interface FLImageView : NSImageView <FLFormImageProtocol>
@end
這做到了謝謝! –