我有一个按钮构造函数类,在那个类中我有这个方法来设计我的按钮
- (void)setupWithPosition:(CGPoint)point withImage:(UIImage *)image withImageFloat:(NSString *)imageFloat withTitle:(NSString *)title withLineWidth:(CGFloat)lineWidth respondsToSelector:(NSString*)selector
{
// create button
ButtonWithImage* button = [[ButtonWithImage alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
//[button setTitle:[title uppercaseString] forState:UIControlStateNormal];
[button setupViewWithText:title andImage:image andImageFloat:imageFloat];
[button addTarget:self
action:NSSelectorFromString(selector)
forControlEvents:UIControlEventTouchUpInside];
CGRect buttonFrame = button.frame;
CGFloat lineX = 0.0f;
// setup image
if ([[imageFloat lowercaseString] isEqualToString:@"right"]) {
lineX = buttonFrame.origin.x + buttonFrame.size.width;
} else {
lineX = 0.0f;
buttonFrame.origin.x = lineWidth;
button.frame = buttonFrame;
}
self.line = [[UIView alloc] initWithFrame:CGRectMake(lineX, buttonFrame.size.height/2, lineWidth, LINE_HEIGHT)];
self.line.backgroundColor = [UIColor lineNormalColor];
[self addSubview:self.line];
[self addSubview:button];
}
我使用以下方法调用它:
homepageButtons = [[NSMutableArray alloc] init];
CategoryButtonView* za = [[CategoryButtonView alloc] initWithFrame:CGRectMake(200, 250, 300, 46)];
[za setupWithPosition:CGPointMake(100, 100) withImage:[UIImage imageNamed:@"zas.png"] withImageFloat:@"right" withTitle:@"za" withLineWidth:80.0f respondsToSelector:@"buttonClicked"];
按钮放置正确,但是当我点击它们时,我得到了那个错误
CategoryButtonView buttonClicked]: unrecognized selector sent to instance 0xa1a46a0
2012-11-02 17:53:43.844 Man[3432:14c03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CategoryButtonView buttonClicked]: unrecognized selector sent to instance 0xa1a46a0'
我想这是一个 SEL 问题,我该如何解决?