我现在知道 Objective-C 中没有受保护的方法,这是我的问题。我有两个具有许多共享功能和属性的视图控制器。我的愿景是拥有一个 BaseViewController 来保存共享方法和属性,并且两个类将继承并覆盖所需的功能,同时使用相同的变量, 我不希望通过将共享函数放在 . h 文件
为了帮助澄清我的问题,我正在添加代码:)
@interface BaseViewController ()
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *uiButtons;
- (void)setBtns:(NSArray *)p_btns; //tried with & without this line
@end
@implementation BaseViewController
- (void)setBtns:(NSArray *)p_btns {
uiButtons = p_btns;
//do something generic with the buttons (set font, image etc.)
}
@end
@interface DerivedViewController ()
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *buttonsConnectedToTheActualView;
@end
@implementation DerivedViewController
- (void) setBtns:(NSArray *)p_btns {
[super setBtns:p_btns];
//do something specific with the buttons (decide if they face up or down according to this class logic)
}
@end
调用[super setBtns:p_btns];
引发错误:
DerivedGameViewController.m:No visible @interface for 'BaseViewController' declares the selector 'setBtns:'
我怎样才能做到这一点?有人可以发布一个片段或指出我的错误(在代码或概念中)。