【发布时间】:2015-07-31 22:41:31
【问题描述】:
我创建了一个带有一些标签和一个按钮的 UIView .xib。我连接了按钮的所有插座和 IBAction。
当我从视图控制器添加 .xib 子视图时,它显示正常,但按钮不起作用。
这是我的 xib 的 .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;
}
我已经尝试了你能想象到的一切,但没有结果
谢谢
【问题讨论】:
-
你的 .xib 有一个 UIViewController 还是只有一个 UIView ?
-
我错误地创建了 .xib 对象,当我使用这个方法时它工作正常 NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"AgregarAlCarrito" owner:self options:nil]; UIView *mainView = [subviewArray objectAtIndex:0];
标签: ios objective-c uibutton xcode6 xib