UIButton的自定义属性(iphone sdk)

Mat*_*cer 1 iphone uibutton

我已经为UIButton创建了一个子类,并希望将自定义属性传递给它.然而,它不起作用,我已经读过,继承UIButton并不是一个好主意.

我的问题是如何为按钮分配自定义属性?我正在创建一个按钮,该按钮被放置在分组表的标题视图中.我想传递给那个按钮的节号.我已经在每行中使用UISwitch成功完成了此操作,但不能对UIButton使用相同的方法.

所以我创建了一个按钮

MattsButtonClass *button = [MattsButtonClass buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(240, 15, 45, 30);
button.MFsectionNo = section; //this would be 1, 2 etc
//etc
Run Code Online (Sandbox Code Playgroud)

那么我该怎么做呢?你会看到我的UI按钮有一个子类,看起来像这样

//.h file
@interface MattsButtonClass : UIButton {
    int MFsectionNo;
}

@property (nonatomic) int MFsectionNo;

@end

//.m file
@implementation MattsButtonClass

@synthesize MFsectionNo;


@end
Run Code Online (Sandbox Code Playgroud)

上面的错误是

-[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'
Run Code Online (Sandbox Code Playgroud)

我不想做什么?谢谢你的帮助...

Tho*_*ler 5

您可能只是使用tag属性UIButton来存储您的节号(可能有一个偏移量,因为tag默认情况下为0)