I have created a subclass for a UIButton and was hoping to pass a custom property to it. However, it's not working and I've since read that subclassing a UIButton isn't a great idea.
MY question is how do I assign a custom property to a button? I am creating a button which is being placed in the headerview of a grouped table. I want to pass to that button the section number. I've done this successfully with a UISwitch in each row, but can't use the same method for the UIButton.
So I create a button
MattsButtonClass *button = [MattsButtonClass buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(240, 15, 45, 30);
button.MFsectionNo = section; //this would be 1, 2 etc
//etc
So how do I actually do this? you'll see that my UIbutton has a subclass, which looks like this
//.h file
@interface MattsButtonClass : UIButton {
int MFsectionNo;
}
@property (nonatomic) int MFsectionNo;
@end
//.m file
@implementation MattsButtonClass
@synthesize MFsectionNo;
@end
The error on the above is
-[UIRoundedRectButton MFsectionNo:]: unrecognized selector sent to instance 0x5673650
2010-09-07 22:41:39.751 demo4[67445:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIRoundedRectButton MFsectionNo:]: unrecognized selector sent to instance 0x5673650'
Is what I am trying not possible? Thanks for any help...