我已经创建了一个带有一些标签和按钮的UIView .xib。我连接了按钮的所有出口和IBAction。
当我从我的视图控制器添加。xib子视图时,它显示ok,但按钮不起作用。
这是我的。m文件
-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
if(self = [super initWithCoder:aDecoder])
{
[self load];
}
return self;
}
-(instancetype)initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame])
{
[self load];
}
return self;
}
-(void)load
{
[[self superview] setUserInteractionEnabled:YES];
[self setUserInteractionEnabled:YES];
UIView *view = [[[NSBundle bundleForClass:[self class]] loadNibNamed:@"AgregarAlCarrito" owner:self options:nil] firstObject];
[self addSubview:view];
view.frame = self.bounds;
}
我已经尝试了所有你能想到的结果
谢谢
所以这一行看起来很可疑:
[self addSubview:view];
您应该将xib视图添加到父视图。我在我的一个应用中做了这样的事情,我有这样的东西:
[[self view] addSubview:_xibView];