我正在創建多個不同的 UI 子類,這些子類可以使用 來創建JSContext,我希望它們都繼承一組特定的方法。
班級從NSButton到NSTextView。將單個子類用作NSView父類會很好,但我不知道這是否可能 - 或者如何開始搜索。
例如:
@interface CustomButtonClass : NSButton
我正在尋找一種NSButton從自定義NSView子類繼承的方法。
有沒有辦法解決這個問題,還是我需要創建多個中間類?
uj5u.com熱心網友回復:
答案非常明顯,但是來自不同的語言,我很難建立聯系。感謝所有的評論,這很容易弄清楚。
您可以為NSView. 類別還可以包括所有必需的協議。
例如,就我而言,我想向 公開多個NSView方法JSContext,并創建一些我自己的方法,這些方法適用于任何NSView派生物件。
@protocol JSInterfaceExports <JSExport>
// Anything you want to expose to JS
- (void)customMethod;
// You can also expose all the common NSView properties
// and methods to JS in this protocol
@property (nonatomic) NSRect frame;
- (void)removeFromSuperview;
@end
@interface NSView (JSInterface)
// Any custom methods and properties
- (void)customMethod;
@end
將此檔案包含在任何子NSView類中,使它們符合<JSInterfaceExports>,然后就設定好了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/379821.html
