【发布时间】:2013-03-04 22:25:36
【问题描述】:
我现在知道 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:'
我怎样才能做到这一点?有人可以发布一个 sn-p 或指出我的错误(在代码或概念上)。
【问题讨论】:
标签: objective-c uiviewcontroller derived-instances