I’m trying to sub class the uibutton class and add some extra metheds to it.
If I ceate a class as follows
cTest *mTest=[cTest buttonWithType:UIButtonTypeRoundedRect];
and call any methed, one i created or allready there, example [cTest setTitle:@"test" forState: UIControlStateNormal]; crashes.
my cTest class:
#import <Foundation/Foundation.h>
@interface cTest : UIButton {
int i;
}
-(void) aTest;
@end
code to test the class:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
// this works fine
UIButton *mBut=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[mBut setTitle:@"test" forState: UIControlStateNormal];
// this does NOT
cTest *mTest=[cTest buttonWithType:UIButtonTypeRoundedRect];
[cTest setTitle:@"test" forState: UIControlStateNormal];
[mTest aTest]; // crashes here does not call my function
}
Ted
UIButton buttonWithType: simply returns a UIButton* object, not a cTest* object.
You wil have to provide a class method (factory method)
+ (cTest*) cTestWithType:
That one does not call [super buttonWithType:…] neither.
Instead of that you will have to create a new cTest object with alloc (and retain or autorelease, what ever serves your purpose best) and initialize it by setting the buttonType property.
… or just do the same without providing a factory method.