inherit methods declared in .m file

扶醉桌前 提交于 2019-12-08 07:48:46

问题


I now know there is no protected method in objective-c and here is my problem: I have two viewControllers with many functions and properties that are shared, my vision was to have a BaseViewColntroller holding the share methods and properties and from it two classes will inherit and override the needed functionality while using the same variables, I don't wish to convert the shared functions to public by placing them in the .h file

to help clarify my question i'm adding code :)

@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

the call to [super setBtns:p_btns]; raise an error: DerivedGameViewController.m:No visible @interface for 'BaseViewController' declares the selector 'setBtns:'

how can i achieve this? can someone post a snippet or point to my mistake (in code or concept)

Thanks


回答1:


Just create a second header with the protected methods declared in a category. Name and document the header appropriately.

UIGestureRecognizer.h and UIGestureRecognizerSubclass.h may server you as an example.



来源:https://stackoverflow.com/questions/15212321/inherit-methods-declared-in-m-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!