这开始是一个简单的问题,但我无法解决它。我已经将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];
它似乎不起作用。有什么建议吗?
答案 0 :(得分:1)
好像忘了给super
打电话。变化:
self = [self initWithFrame:frame];
为:
self = [super initWithFrame:frame];