我有一个自定义按钮类:
自定义按钮.h 文件:
@interface CustomButton : UIButton
@property (nonatomic, retain) NSString* info;
@end
自定义按钮.m 文件:
#import "CustomButton.h"
@implementation CustomButton
@synthesize info;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@end
在我的主视图控制器中:
CustomButton* btn = [CustomButton buttonWithType:UIButtonTypeDetailDisclosure];
[btn setInfo:@"foobar"];
NSLog(@"%@", [btn info]);
[self.view addSubview:btn];
如果它只是一个简单的按钮 ( [CustomButton new]
),我不会收到任何错误。但是如果我选择buttonWithType:UIButtonTypeDetailDisclosure
我会得到这个错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UIButton setInfo:]: unrecognized selector sent to instance 0x753c8c0'
为什么会这样?