2013-03-04 38 views
1

我现在知道在objective-c中没有受保护的方法,这里是我的问题: 我有两个viewController具有许多共享的函数和属性,我的愿景是让一个BaseViewColntroller持有共享的方法和属性,并从中两个类将继承和同时使用相同的变量将覆盖所需的功能, 我不希望通过将它们放置在.h文件的共享功能转换为公共在.m文件中声明的继承方法

以帮助澄清我的问题,我添加代码:)

@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:'

我该如何做到这一点?可有人张贴片段或点我的错误(代码或概念)

感谢

回答

4

只需创建一个类中声明的保护方法第二集。适当命名并记录标题。

UIGestureRecognizer.h和UIGestureRecognizerSubclass.h可能会以服务器为例。

+0

我不确定这是我在找什么,所以我通过添加代码来编辑我的问题,如果你可以再看看我真的很感激它:) – 2013-03-06 00:12:33