这开始是一个简单的问题,但我无法解决。我已经对 UIButton 进行了子类化(我知道,有争议),但我似乎无法让它正常工作。我的 UIButton 子类如下所示:
。H
@interface SocialButton : UIButton
@property (nonatomic, strong) CustomClass *cust;
- (id)initWithObject:(CustomClass *)custom andFrame:(CGRect)frame;
@end
.m
@implementation SocialButton
@synthesize custom=_custom;
- (id)initWithObject:(CustomClass *)custom andFrame:(CGRect)frame;
{
self = [self initWithFrame:frame];
if (self)
{
[self addTarget:self action:@selector(buttonTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
self.backgroundColor = [UIColor blueColor];
self.cust = custom;
}
return self;
}
@end
后来,当我尝试从此类创建一个按钮时,如下所示:
SocialButton *social = [[SocialButton alloc] initWithObject:object andFrame:frame];
它似乎不起作用。有什么建议么?