继承.m文件中声明的方法

时间:2013-03-04 22:25:36

标签: objective-c uiviewcontroller derived-instances

我现在知道objective-c中没有受保护的方法,这是我的问题: 我有两个viewControllers,它们有许多共享的函数和属性,我的愿景是让一个BaseViewColntroller保存共享方法和属性,从中有两个类将继承并覆盖所需的功能,同时使用相同的变量, 我不希望将共享功能转换为公共,方法是将它们放在.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:'BaseViewController'没有可见的@interface声明选择器'setBtns:'

我怎样才能做到这一点?有人可以发布一个片段或指出我的错误(代码或概念)

由于

1 个答案:

答案 0 :(得分:4)

只需使用在类别中声明的受保护方法创建第二个标头。适当地命名并记录标题。

UIGestureRecognizer.h和UIGestureRecognizerSubclass.h可以为您提供服务。