I'm having trouble transferring my thoughts on class inheritance. I support creating an interface in the form of a panel, for example, in an application, and I will have 10 widgets / dashlets in this panel view. All of these dashlets / widgets will have basically the same look, with a title at the top, borders, a row of buttons at the top and a graph. Let's say I create a subclass of the UI View called "Dashlet" with properties and outputs and create a XIB file with the proper location and connected outputs, etc.
Now I want to create several subclasses of this "Dashlet" view, which will process the data differently and draw different graphs. My current code looks something like this:
Dashlet.h
@interface Dashlet : UIView{ @private UILabel *title; UIView *controls; UIView *graph; } @property (weak, nonatomic) IBOutlet UILabel *title; @property (weak, nonatomic) IBOutlet UIView *controls; @property (weak, nonatomic) IBOutlet UIView *graph; -(Dashlet*)initWithParams:(NSMutableDictionary *)params; -(void)someDummyMethod; @end
And in Dashlet.m
- (id) init { self = [super init]; //Basic empty init... return self; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { } return self; } -(id)initWithParams:(NSMutableDictionary *)params { self = [super init]; if (self) { self = [[[NSBundle mainBundle] loadNibNamed:@"Dashlet" owner:nil options:nil] lastObject]; //some init code } return self; }
Now let's say that I create a subclass of CustomDashlet.h:
@interface CustomDashlet : Dashlet @property (nonatomic, strong) NSString* test; -(void)testMethod; -(void)someDummyMethod; @end
and CustomDashlet.m
-(id)init{ return self; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { } return self; } -(id)initWithParams:(NSMutableDictionary *)parameters { self = [super initWithParams:parameters]; if (self) {
This seems to work, but I need to override some of the methods declared in the superclass, or even add some of my own. Whenever I try to do something like this in CustomDashlet.m
[self someDummyMethod] or even [self testMethod] I get an exception error as follows:
NSInvalidArgumentException', reason: '-[Dashlet testMethod]: unrecognized selector sent to instance
Am I even doing this right? Did I miss something? Should I do this work in some other way? If anyone has any suggestions, please feel free to share your thoughts, thank you for your help.